0
Private Sub Worksheet_Change(ByVal Target As Range)

Dim c As Range

For Each c In Target.Cells
   **If c.Value <> Empty Or c.Value = 0 Then
   End If**
   If c.Column = 11 Then
   c.Offset(0, -1).Value = Now()
 
 End If
 Next c

End Sub

我上面的代码运行良好,除了我试图添加粗体代码以忽略任何空白单元格(也可以是忽略 0 值单元格的选项,但不是必需的)。

4

2 回答 2

0

您的两个论点似乎以不同的方式进行,因为您将两者混为一谈<> Empty=0在同一个测试中。

无论如何,如果单元格中除了 0 之外还有其他内容,则会进行更改,并且作为奖励,如果单元格为空或 0,则会清除更改。

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range

Application.EnableEvents = False
For Each c In Target.Cells
    If c.Column = 11 Then
        If c.Value = "" Or c.Value = 0 Then
            c.Offset(0, -1).ClearContents
        Else
            c.Offset(0, -1).Value = Now()
        End If
    End If
Next c
Application.EnableEvents = True
End Sub
于 2013-06-18T20:03:39.123 回答
0
If c.Value != ""

应该适用于空白单元格。

至少它在这里工作。

至于忽略值 0,您不能将 if 子句更改为if c.Value > 0吗?

于 2013-06-18T19:57:32.953 回答