VBA - AutoFilter error

lucausa75

New Member
Joined
Oct 15, 2021
Messages
22
Office Version
  1. 2013
Platform
  1. Windows
Dear all,

I'm trying to run this VBA code

VBA Code:
Private Sub cmdCheck_Click()
    Dim i As Long
    Dim PRDFromCombo() As Variant
    Dim Ord As Long
    Dim MyArray() As Variant
    Dim MyValue As Variant
    
    Application.Cursor = xlWait
    For i = 0 To (cboPRD.ListCount - 1)
        If CDate(cboPRD.List(i)) <= CDate(cboPRD.Text) Then
            Ord = Ord + 1
            ReDim Preserve PRDFromCombo(1 To Ord)
            PRDFromCombo(Ord) = Format(CDate(cboPRD.List(i)), "mm/dd/yyyy")
        End If
    Next i

    ReDim MyArray(1 To UBound(PRDFromCombo) * 2)
    For i = 1 To UBound(PRDFromCombo) * 2
        If i Mod 2 = 0 Then
            MyValue = PRDFromCombo(i / 2)
        Else
            MyValue = 2
        End If
        MyArray(i) = MyValue
    Next i

    ActiveWorkbook.Sheets("Details").ListObjects("Table_Query_from_AGSV2").Range.AutoFilter Field:=17, Operator:=xlFilterValues, Criteria2:=MyArray
    Application.Cursor = xlDefault
End Sub

which it works but when I open the excel file I get this error:


and when I click "Yes" I get this message:


I think it is something depending on the variable because If I change Dim MyValue As Date to Dim MyValue As Variant I get this error:


Any suggestion to solve this issue?

Thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,215,035
Messages
6,122,791
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top