当新值是特定单元格的键时,“结果单元格”应使用其公式更新新值。但是,仅在使用宏时才更新“结果单元格”。请帮助我,非常感谢。
Sub testing()
Dim lastrow As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row 'assume i count the row
Range("J" & lastrow).Select 'this is the output cell
ActiveCell.Formula = Range("H" & lastrow).Value / 4000 'assume this is the formula, i try to get value from Col'H' & my lastrow then divide by 4000
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
Excel解决方案:
另一种方法。要将函数用作列J中的=INDEX(H:H,COUNTA(A:A))/4000
。这将为您提供与宏一样的确切结果,并且会自动更新。
VBA解决方案:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("J:J")) Is Nothing Then
Dim lastrow As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).row
Range("J" & lastrow).formula = Range("H" & lastrow).Value / 4000
End If
End Sub