excel Worksheet_Change事件的应用问题
当L列的日期小于系统时间时,触发Worksheet_Change事件,实现效果为后几列的数据选择性粘帖成数值,应该怎么写...
当L列的日期小于系统时间时,触发Worksheet_Change事件,实现效果为后几列的数据选择性粘帖成数值,应该怎么写
展开
展开全部
虽然比较乱了点,但是好像可以实现你要的功能。
试试吧。
Dim flg As Integer
Private Sub Worksheet_Change(ByVal Target As Range)
Const COL_DATE = 12 ' column of date (L)
Const COL_COPY_FROM = 13 ' from column (M)
Const COL_COPY_TO = 26 ' to colume (Z)
Dim t_day As Date
t_day = Date
Application.ScreenUpdating = False
start_row = 1
'防止死循环
If flg = 1 Then
Exit Sub
End If
flg = 1
Do While Cells(start_row, COL_DATE).Value <> ""
If Cells(start_row, COL_DATE).Value < t_day Then
Range(Cells(start_row, COL_COPY_FROM), Cells(start_row, COL_COPY_TO)).Select
Selection.Copy
Range(Cells(start_row, COL_COPY_FROM), Cells(start_row, COL_COPY_TO)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
start_row = start_row + 1
Loop
Application.CutCopyMode = False
flg = 0
Target.Select
Application.ScreenUpdating = False
End Sub
试试吧。
Dim flg As Integer
Private Sub Worksheet_Change(ByVal Target As Range)
Const COL_DATE = 12 ' column of date (L)
Const COL_COPY_FROM = 13 ' from column (M)
Const COL_COPY_TO = 26 ' to colume (Z)
Dim t_day As Date
t_day = Date
Application.ScreenUpdating = False
start_row = 1
'防止死循环
If flg = 1 Then
Exit Sub
End If
flg = 1
Do While Cells(start_row, COL_DATE).Value <> ""
If Cells(start_row, COL_DATE).Value < t_day Then
Range(Cells(start_row, COL_COPY_FROM), Cells(start_row, COL_COPY_TO)).Select
Selection.Copy
Range(Cells(start_row, COL_COPY_FROM), Cells(start_row, COL_COPY_TO)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
start_row = start_row + 1
Loop
Application.CutCopyMode = False
flg = 0
Target.Select
Application.ScreenUpdating = False
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询