我在Excel中编写了一个简单的宏,该宏记录了带有日期的单元格中的更改。 当单元格中的值被键入或通过公式更改时,宏将起作用。
当我使用来自Bloomberg API的动态数据,并且数据在Excel中发生更改时,宏无法识别单元格中的更改,也不会记录该更改。
Dim xVal As String
Dim iVal As Integer
Private Sub Worksheet_Change(ByVal Target As Range)
Static xCount As Integer
iVal = Application.WorksheetFunction.Count(Range("F:F"), 1)
xCount = iVal
Application.EnableEvents = False
If Target.Address = Range("C2").Address Then
Range("E3").Offset(xCount, 0).Value = Range("C2").Value
Range("F3").Offset(xCount, 0).Value = Now
xCount = xCount + 1
Else
If xVal <> Range("C2").Value Then
Range("E3").Offset(xCount, 0).Value = Range("C2").Value
Range("F3").Offset(xCount, 0).Value = Now
xCount = xCount + 1
End If
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
xVal = Range("C2").Value
End Sub