Question : Excel VBA Array within an Array

I am attempting to autofilter a set of records with an array, but the array is made up of other arrays.  The filter won't work because it is looking for the value in the last array.  I'm trying to filter on the values from the array within the last array.  I know it's possible, but need a fresh set of eyes that aren't as tired as mine.

TIA!

Public Sub reg(brand As String, srArray1, srArray2, srArray3, srArray4, srArray5, srArray6)
'
    On Error GoTo ErrorHandler

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim i As Long
    Dim SRrange As Range
    Dim NE As Variant, MA As Variant, SE As Variant, CE As Variant, CW As Variant, WE As Variant
    Dim SRConditions As Variant

    If srArray1 = True Then
        NE = VBA.Array("CT", "DE", "MA", "ME", "NH", "NJ", "NY", "PA", "RI", "VT")
    Else: NE = ""
    End If
    If srArray2 = True Then
        MA = VBA.Array("DC", "MD", "SE", "NC", "SC", "VA")
    Else: MA = ""
    End If
    If srArray3 = True Then
        SE = VBA.Array("FL", "GA", "SE", "MS", "PR", "TN", "VI")
    Else: SE = ""
    End If
    If srArray4 = True Then
        CE = VBA.Array("IN", "KY", "MI", "OH", "WV")
    Else: CE = ""
    End If
    If srArray5 = True Then
        CW = VBA.Array("IA", "IL", "MN", "MO", "ND", "SD", "WI")
    Else: CW = ""
    End If
    If srArray6 = True Then
        WE = VBA.Array("AK", "AR", "AZ", "CA", "CO", "HI", "ID", "KS", "LA", "MT", "NM", "NV", "OK", "OR", "TX", "UT", "WA", "WY")
    Else: WE = ""
    End If
   
    SRConditions = VBA.Array(NE, MA, SE, CE, CW, WE)

    'autofilter here with the passed brand variable sheet and subregions
    With Sheets(brand)
   
        Set SRrange = Range("A3").CurrentRegion

        If .AutoFilterMode = True Then
            .AutoFilterMode = False
            For i = 0 To 5
                SRrange.AutoFilter FIELD:=32, Criteria1:=SRConditions(i)
            Next i
        Else
            For i = 0 To 5
                SRrange.AutoFilter FIELD:=32, Criteria1:=SRConditions(i)
            Next i
        End If
       
    End With

    UserForm7.Hide
    DoEvents

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

Exit Sub
ErrorHandler:
    MsgBox "Error: " & Err.Number & " , " & Err.Description & Chr(13) & _
    "Procedure is: reg" & Chr(13) & ""
'
End Sub

Answer : Excel VBA Array within an Array

Me thinks if no check boxes are checked then you show all:

        Dim Checked As Boolean
        For arIndex = 1 To 6
            srArray(arIndex) = Me.Controls("CheckBox" & arIndex).Value
            Checked = srArray(arIndex) Or Checked
        Next
        If Not Checked Then
            For arIndex = 1 To 6
                srArray(arIndex) = True
            Next
        End If

Kevin
Random Solutions  
 
programming4us programming4us