Hi,
The following code is intended to loop through a list of dates, format them into "YYYY"-format, check if there's an identical item in the array yet, add any new items to the array and write it to a worksheet. It returns 'runtime error 5 invalid procedure call or argument', though.
Could you help me get this to work, please? Thanks!
The following code is intended to loop through a list of dates, format them into "YYYY"-format, check if there's an identical item in the array yet, add any new items to the array and write it to a worksheet. It returns 'runtime error 5 invalid procedure call or argument', though.
Code:
Private Sub cmd_try_Click()
Dim dataRange As Range
Dim oneCell As Range
Dim newYear As String
Dim arr_years() As String
Dim i As Integer
Set dataRange = Range(Sheets("Overzicht_aanmeldingen").Cells(4, 10), Sheets("Overzicht_aanmeldingen").Cells(4, 10).End(xlDown))
For Each oneCell In dataRange
If Not IsError(Application.Match(oneCell.Value, arr_years, 0)) Then
i = i + 1
newYear = CStr(Year(oneCell.Value))
ReDim Preserve arr_years(1 To i)
arr_years(i) = newYear
Else: Exit For
End If
Next oneCell
Sheets("Aanmeldingen_per_maand").Range("B2", Range("B2").End(xlToRight)) = arr_years
End Sub
Could you help me get this to work, please? Thanks!