我一直在尝试编写一小段代码来验证以确认日期是否包含在数组中。我已经能够滚动浏览代码,If lists(i) = TodaysDate Then
直到lists(i)
显示subscript out of range
. 我已通过 Internet 搜索,但无法解决此问题。
我的宏内容如下:
Sub size_an_array()
Dim i As Integer
Dim Range_of_Dates As Integer
Dim TodaysDate As Variant, finish As String
TodaysDate = Range("Sheet11!c2")
ThisWorkbook.Worksheets("Sheet11").Activate
lists = Range("Processed_Dates")
Range_of_Dates = UBound(lists, 1) - LBound(lists, 1) + 1
For c = 1 To UBound(lists, 1) ' First array dimension is rows.
For R = 1 To UBound(lists, 2) ' Second array dimension is columns.
Debug.Print lists(c, R)
Next R
Next c
x = Range_of_Dates 'UBound(lists, 1)
ReDim lists(x, 1)
i = 1
Do Until i = x
If lists(i) = TodaysDate Then
Exit Do
End If
Loop
MsgBox "The date has not been found"
End Sub
我比较陌生VBA
,我一直在尝试使用命名范围来拉入数组,但我完全不知道如何解决这个问题。
任何帮助将不胜感激。