删除其他单元曾经使用的单元格的值

我想在一个cell("A1")input一个值cell("A1")那么这个单元格将与A3的值相乘,新的值将会replaceA3A1被清除。

我已经input了下面的代码,但它只做整列,我想它适用于整个列和行从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 

 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模块中:

在这里输入图像说明

似乎testing好:

在这里输入图像说明

你可以使用这样的东西:

 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 

你可以用这个。

 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