vba - 如何通过函数检测给定单元格值的变化
问题描述
我喜欢你给我的以下问题的解决方案:我有一个单元格中随机变化的财务数据,说A1,由财务软件提供,我想将这些数据一个接一个地记录在一个列中,我已经写了这个小代码,但它没有检测到 A1 值的变化,因为单元格 A1 包含软件提供的功能
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("A1"), Range(Target.Address)) Is Nothing Then
Call test
End If
End Sub
Sub test()
Static n As Integer
n = Cells(1, 3).Value ' used for the faste verification of empty cells
While Not IsEmpty(Cells(n, 1))
n = n + 1
Wend
Cells(n, 1).Value = Cells(1, 1).Value
Cells(1, 3).Value = n
End Sub
解决方案
一种简单的方法是创建一个函数,将您要跟踪的单元格作为参数。这样,对单元格值(参数)的更改将生成对跟踪函数的调用。
像这样的东西将跟踪函数被调用的次数:
Dim i As Integer
Function tracker(c As Variant) As Integer
i = i + 1
tracker = i
End Function
推荐阅读
- java - 批处理:使用目录中类型的第一个文件作为变量
- python - TF2.0中如何将tf.data.Dataset类型的数据切片到一定长度?
- ios - 从 Swift 中的循环中删除一个项目
- javascript - 在 Netlify 上部署 Angular 网站时出现空白页面
- python - 对熊猫中的两个对象列求和
- excel - Excel VBA MSXML2.XMLHTTP60 PUT 请求在“发送”操作时失败
- excel - 如何更改自动增量代码的起始值
- ssl - 如何使用 HTTPS 健康检查忽略 SSL 证书
- python-3.x - 当我添加秒时,dict 中的列表被覆盖。列出听写
- php - 试图从 Auth::user 数组中获取特定列