我想调整以下代码,但是我不知道该怎么做...我在这里搜索了一些线程(“合并两个Private Sub Worksheet”,但是到目前为止,我还没有找到可行的解决方案。< / p>
由于我的VBA技能......有限,所以我恳请您的帮助。
enter code here
Private Sub Worksheet_Change(ByVal Target As Range)
Const Spalte As Integer = 17
Dim C As Range
If Not Intersect(Target, Columns(Spalte)) Is Nothing Then
Set Target = Intersect(Target, Columns(Spalte))
For Each C In Target
C.Offset(0, 1).Value = Format(Date, "dd.mm.yyyy") & " um" &
Format(Now(), " hh:mm:ss") & " durch " &
ActiveWorkbook.BuiltinDocumentProperties(7)
Next
End If
Set C = Nothing
End Sub
我现在要做的就是调整它,因此它还会检查第16列是否被更改。如果第16或17列被更改,则应在第18栏中写上日期,依此类推。
非常感谢您的帮助!
答案 0 :(得分:1)
这是一种方法:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range
Dim C As Range
Set r = Range("P:Q")
If Not Intersect(Target, r) Is Nothing Then
For Each C In Intersect(Target, r)
Cells(C.Row, 18).Value = Format(Date, "dd.mm.yyyy") & " um" & _
Format(Now(), " hh:mm:ss") & " durch " & ActiveWorkbook.BuiltinDocumentProperties(7)
Next
End If
Set C = Nothing
End Sub