我想在cell("A1")
中输入一个值,然后该单元格将乘以A3
的值,新值将替换为A3
。 A1
已被清除。
我输入了以下代码,但它只执行整个列,我希望它适用于整个列,行数从20 T2
一直到AP2
所以42
Private Sub worksheet_change(ByVal target As Range)
If target.Column = 20 And target.Value > 0 Then
Dim val As Double
val = target.Value
target.Value = 0
Cells(target.Row, target.Column - 1).Value = val + Cells(target.Row, target.Column - 1).Value
End If
End Sub
答案 0 :(得分:0)
您可以使用以下内容:
Dim flagProgram As Boolean
Private Sub worksheet_change(ByVal target As Range)
Dim dblResult As Double
If flagProgram = False Then
flagProgram = True
dblResult = Cells(1, 1) * Cells(1, 3)
Cells(1, 1) = ""
flagProgram = False
End If
End Sub
答案 1 :(得分:0)
你可以使用它。
Private Sub worksheet_change(ByVal target As Range)
Dim rng As Range
Dim db As Double
Set target = Range("a1")
If target.Value > 0 Then
db = target.Value * Cells(1, 3)
MsgBox db
target.Value = ""
End If
End Sub
答案 2 :(得分:0)
Private Sub worksheet_change(ByVal target As Range)
If target.Address = "$A$1" And target.Value > 0 Then
Dim val As Double
val = target.Value
Range("A1").Value = 0
Cells(3, 1) = val * Cells(3, 1)
End If
End Sub
添加到Sheet1模块中:
似乎测试好了: