AutoFilter Field # - How do numeric designations work?

hip2b2

Board Regular
Joined
May 5, 2003
Messages
117
I am using the following code, works just fine. My question has to do with the field designation.

VBA Code:
 .AutoFilter Field:=11, Criteria1:="=Closed" & strName & "*", Operator:=xlAnd
 .Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
 .AutoFilter Field:=11

The field that contains the filter criteria is Col S. As S is not the 11th letter of the alphabet how does this work? I do note that Col S is the 11th Col in my spreadsheet that is populated with text, or am I drawing a false conclusion?

Is there any simple way to modify the code to relate to an absolute column designation?

Thanks

hip
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,544
Office Version
  1. 365
Platform
  1. Windows
It is the column index, where the first filtered column is 1. So 11 is the 11th column in the autofilter, which suggests your data starts in col I
 

hip2b2

Board Regular
Joined
May 5, 2003
Messages
117
It is the column index, where the first filtered column is 1. So 11 is the 11th column in the autofilter, which suggests your data starts in col I

Well that makes more sense that what I was supposing.

While there is data in Col I it is definitly not the data that is being filtered.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,544
Office Version
  1. 365
Platform
  1. Windows
While there is data in Col I it is definitly not the data that is being filtered.
No but it sounds as though col I is the 1st column in the auto filter range.
 

hip2b2

Board Regular
Joined
May 5, 2003
Messages
117

ADVERTISEMENT

Ahah!!!???? So to do what I should have done, here is the rest of the code:

VBA Code:
Set h = Sheets("For XYZ")
If h.AutoFilterMode Then h.AutoFilterMode = False
lr = Columns("A:K").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
With h.Range("A6:K" & lr)

.AutoFilter Field:=2, Criteria1:="=Open" & strName & "*", Operator:=xlAnd
.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
.AutoFilter Field:=2

.AutoFilter Field:=11, Criteria1:="=Closed" & strName & "*", Operator:=xlAnd
.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
.AutoFilter Field:=11

Not sure how to set the range properly

Thanks again
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,544
Office Version
  1. 365
Platform
  1. Windows
You need to qualify the line getting the last row with the sheet like
VBA Code:
lr = h.Columns("A:K").Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 

hip2b2

Board Regular
Joined
May 5, 2003
Messages
117
Not quite sure what to do with this. I tried to change the range from A:K to A:S and the Field from 11 to 19 but the macro fails at that point.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,544
Office Version
  1. 365
Platform
  1. Windows
What is the range you want to filter & which columns?
 

Watch MrExcel Video

Forum statistics

Threads
1,129,514
Messages
5,636,785
Members
416,940
Latest member
JohanT

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
Top