I am mostly experienced in other programming languages like java and C++. VBA is still very new to me and I hardly know what I'm doing. I attempted to return an arraylist from a function and I keep getting error 5 - invalid procedure call or argument.
Dim months As ArrayList
Dim temp As Integer
Set months = New ArrayList
'Copy and Paste State and Quarter Specific Data
Sheets("The Data (2)").Select
ActiveSheet.Range("$A:$T").AutoFilter Field:=6, Criteria1:=stateName
months = getMonths(Year, Quarter)
ActiveSheet.Range("$A:$T").AutoFilter Field:=17, Criteria1:=months.Item(0), Operator:=xlOr, Criteria2:=months.Item(1), Operator:=xlOr, Criteria3:=months.Item(2)
Range("$A$1:$$T$1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("State Rate Planning Template.xlsm").Activate
Sheets(3).Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Range("A1").Select
I receive the error at "months = getMonths(Year, Quarter)". Year and Quarter are strings declared above the code I have here.
Here is the function getMonths:
Function getMonths(Year As String, Quarter As String) As ArrayList
Dim i As Integer
Dim month As String
Dim monthList As ArrayList
Set monthList = New ArrayList
If (StrComp(Quarter, "1", compare) = 0) Then
For i = 1 To 3
month = Year & "-0" & i
monthList.Add month
Next i
ElseIf (StrComp(Quarter, "2", compare) = 0) Then
For i = 4 To 6
month = Year & "-0" & i
monthList.Add month
Next i
ElseIf (StrComp(Quarter, "3", compare) = 0) Then
For i = 7 To 9
month = Year & "-0" & i
monthList.Add month
Next i
ElseIf (StrComp(Quarter, "4", compare) = 0) Then
For i = 10 To 12
month = Year & "-" & i
monthList.Add month
Next i
End If
Set getMonths = monthList
End Function
Any help would be appreciated for a VBA newbie :)