Set filter and loop across columns

coop123

Board Regular
Joined
Dec 18, 2018
Messages
66
Office Version
  1. 365
Hi

I have a spreadsheet which has data across 200 columns. this data needs to be filtered on each column and the the totals copied out.

I have written a macro which set the filters and copies data to relevant position, my problem is how to I get the Field number within the filter to change each time a new column is selected.

1610380520009.png


Thanks in advance.

Coop123
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This shows you how to do that:
VBA Code:
Sub Fitr()
   For i = 1 To 10
   ActiveSheet.AutoFilterMode = False
    Columns("A:Q").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$Q$32").AutoFilter Field:=i, Criteria1:=">10", _
        Operator:=xlAnd
    MsgBox ("Filtered on Column " & i)
   Next i
End Sub
 
Upvote 0
Solution
Hi offthelip

thank you for your reply I put into my macro and it partially solved my problem.

I forgot to mention previously that I need to filter every third column not colums next to each other. Is there a way of adding this increment to the code you supplied.

Thanks
 
Upvote 0
Change
VBA Code:
For i = 1 To 10
to
VBA Code:
For i = 3 To 10 Step 3
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,521
Members
449,088
Latest member
RandomExceller01

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