Raj999

New Member
Joined
Dec 16, 2014
Messages
7
Hi All,

I have declared the below

Dim Fltr As String
Dim Component As Integer


Fltr1 = "USA"
Fltr2 = "Ireland"
Fltr3 = "Australia"



and I am trying to loop in by using the above for the filter shown below.



Selection.AutoFilter
ActiveSheet.Range("$A:$U").AutoFilter Field:=2, Criteria1:= _
Fltr & Component


Have I declared string correctly and declared the Values for Fltr1,2 and 3 correctly? is the above Fltr & Component is correct . The macro is not filtering and resulting in blank. Please Help...!!!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
In the code you posted, you declared the variables Fltr and Component, but you have not set them equal to another before trying to use them in your filter. In any event, I think I see what you are trying to do, and don't think you can create enumerated variables on the fly like that. Better to use arrays, i.e.
Code:
    Dim Fltr As Variant
    Dim Component As Integer
    
    Fltr = Array("USA", "Ireland", "Australia")
    
    For Component = LBound(Fltr) To UBound(Fltr)

        Selection.AutoFilter
        ActiveSheet.Range("$A:$U").AutoFilter Field:=2, Criteria1:=Fltr(Component)

    Next Component
 
Last edited:
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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