当另一个单元格变为1时,在单元格中添加值3

时间:2014-09-11 07:26:52

标签: excel vba range cell robot

我将在excel中监控机器人的价值。每次机器人发送值" 1"到我的电脑(在1和0之间切换,因为数字)在excel的单元格A1中显示,值" 3"应添加到单元格B1中。第二次A1变为1时,B1等值应为6。

下面的代码就是这样做的,除非它将值3添加为3,即使它从1切换到0.我只希望它在从0变为1时进行切换。

使用Excel 2007

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A5")) Is Nothing Then Me.Range("B5").Value = Me.Range("B5").Value       + 3

1 个答案:

答案 0 :(得分:0)

If target.Column = 1 and target.Row = 1 then
    If target.Value = 1 Then
        Range("B1").Value = Range("B1").Value + 3
    End If
End if

这应该这样做。