myArray正在存储我在调用Sub过程之前需要检查的数据。它有3列:
我需要检查:
如果是,那么从现在到第2列中相应字符串的最新时间戳的时差是多少
For n = 1 To UBound(myArray, 2)
If myArray(1, n) = myString Then
myTimeStamp = myArray(2, n) 'find the timestamp of this string in col2
myTimeDiff = DateDiff("n", myTimeStamp, DateTime.Now()) ' calculate the time difference in minutes
myIndex = n 'return the array index (n)
End If
Next n
因为数组按时间顺序填充时间戳,所以我知道col1中给定字符串的最新值也是最新的。
但myIndex返回一个空字符串,为什么?
答案 0 :(得分:0)
VBA中的数组通常以LBound = 0开头,因此你的for循环应该是:
For n = 0 to UBound(myArray)
答案 1 :(得分:0)
试试这个
For n = 1 To UBound(myArray, 1)
If myArray(n, 1) = myString Then
myTimeStamp = myArray(n, 2) 'find the timestamp of this string in col2
myTimeDiff = DateDiff("n", myTimeStamp, DateTime.Now()) ' calculate the time difference in minutes
myIndex = n 'return the array index (n)
End If
Next n