【发布时间】:2018-06-19 02:30:31
【问题描述】:
为什么这不起作用? 我正在尝试让 excel 检查 B 列和 D 列中的任何更改,如果 B 列发生更改,然后执行一些操作等等。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lc As Long
Dim TEMPVAL As String
Dim ws1, ws2 As Worksheet
Dim myDay As String
Set ws1 = ThisWorkbook.Sheets("Lists")
myDay = Format(myDate, "dddd")
If Intersect(Target, Range("B:B")) Is Nothing Then Exit Sub
If Target = "" Then Exit Sub
MsgBox "Row: " & Target.Row & "Column: " & lc
With Application
.EnableEvents = False
.ScreenUpdating = False
Cells(Target.Row, lc + 1) = Target.Row - 1
Cells(Target.Row, lc + 3) = Format(myDate, "dd-MMM-yyyy")
Cells(Target.Row, lc + 4) = Application.WorksheetFunction.VLookup(Target, ws1.Range("A2:C29").Value, 3, False)
Cells(Target.Row, lc + 5) = 7.6
Cells(Target.Row, lc + 7) = Application.WorksheetFunction.VLookup(Target, ws1.Range("A2:C29").Value, 2, False)
Cells(Target.Row, lc + 8) = myDay
Cells(Target.Row, lc + 10) = WORKCODE(Target.Row, lc + 4)
.EnableEvents = True
.ScreenUpdating = True
End With
If Intersect(Target, Range("D2:D5002")) Is Nothing Then Exit Sub
If Target = "" Then Exit Sub
MsgBox "Row: " & Target.Row & "Column: " & lc
With Application
.EnableEvents = False
.ScreenUpdating = False
Cells(Target.Row, lc + 10) = WORKCODE(Target.Row, lc + 4)
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Excel 运行第一个 intersec 并退出 sub。 为什么它不运行第二个相交? 提前致谢
【问题讨论】:
标签: vba excel excel-2007