我正在尝试在我的实时 Excel 工作表中学习 VBA。
我有 VBA 代码,第一个得到
运行时错误 13 类型不匹配
在删除多个单元格时,通过少量工作,我在删除多个单元格时没有收到错误,但是当我对多个已删除的单元格执行 UNDO 时,会发生同样的错误。
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 6 Then
ThisRow = Target.Row
If Target.Cells(1).Value = vbNullString Then Exit Sub
If Len(Target.Offset(, -4)) = 0 Then
Range("J" & ThisRow).Value = Time()
Range("B" & ThisRow).Value = Date
Range("AA" & ThisRow).Value = Environ("username")
End If
End If
End Sub
像这样的东西:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rng As Range, c As Range
Set rng = Application.Intersect(Target, Me.Columns(6))
If rng Is Nothing Then Exit Sub
For Each c In rng.Cells
If Len(c.Value) > 0 Then
If Len(c.Offset(0, -4).Value) = 0 Then
With c.EntireRow
.Cells(1, "J").Value = Time()
.Cells(1, "B").Value = Date
.Cells(1, "AA").Value = Environ("username")
End With
End If
End If
Next c
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句