I have the code below to create a dictionary and assign values from
3 columns (i,1) key, and array of dates from getdates() from startdate(i,2) and enddate(i,3).
My goal is to print each date by key (there can be multiple dates for 1 key) but the code below is giving me a type mismatch error.
Sub Test_Dates()
Dim TESTWB As Workbook
Dim TESTWS As Worksheet
Set TESTWB = ThisWorkbook
Set TESTWS = TESTWB.Worksheets("TEST")
Dim Dict As New Scripting.Dictionary
For i = 2 To TESTWS.Cells(1, 1).End(xlDown).Row
Dict.Add TESTWS.Cells(i, 1).Value, getDates(TESTWS.Cells(i, 2), TESTWS.Cells(i, 3))
Next i
For Each Key In Dict.Keys
Dim idate As Variant
For Each idate In Dict.Items
Debug.Print idate 'this line is where the error is
Next idate
Next Key
End Sub
This is get dates function to get array of dates between start and end
Function getDates(ByVal StartDate As Date, ByVal EndDate As Date) As Variant
Dim varDates() As Date
Dim lngDateCounter As Long
ReDim varDates(0 To CLng(EndDate) - CLng(StartDate))
For lngDateCounter = LBound(varDates) To UBound(varDates)
varDates(lngDateCounter) = CDate(StartDate)
StartDate = CDate(CDbl(StartDate) + 1)
Next lngDateCounter
getDates = varDates
End Function