输入新值时,我的Excel单元格值不会更新

时间:2019-08-01 03:22:21

标签: excel vba

当新值是特定单元格的键时,“结果单元格”应使用其公式更新新值。但是,仅在使用宏时才更新“结果单元格”。请帮助我,非常感谢。

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

1 个答案:

答案 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