Need help using AutoFilter on a Range in VBA

califrania

New Member
Joined
Jul 28, 2015
Messages
5
Hi!

Row 3 has a column header labeled "Description" and I want to filter out all cells containing the words "tech" & "qa" in that column. My macro can find the column and the DesRng can find the correct cells

But..my last line of code (with the Auto Filters) will not work :(
I think this is because all the cells contain formulas that pull the text in, rather than the text actually living in cell - but idk how to work around this.

Any help appreciated!


Dim DesCol, LastRow As Integer
Dim DesRng, As Range


Cells(3, 1).Select


Do While ActiveCell <> "Description"
ActiveCell.Offset(0, 1).Select
Loop
DesCol = ActiveCell.Column


LastRow = Cells(rows.Count, DesCol).End(xlUp).Row
Set DesRng = Range(Cells(3, DesCol).Address(), Cells(LastRow, DesCol).Address())


DesRng.AutoFilter Field:=1, Criteria1:="<>*tech*", Operator:=xlAnd, Criteria2:="<>*qa*"
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi,

Are you going to filter only one column?
It seems your spreadsheet has data from columnA.
>Set DesRng = Range(Cells(3, DesCol).Address(), Cells(LastRow, DesCol).Address())
I think this line is not necessary.

ActiveCell
.AutoFilter Field:=DesCol, Criteria1:="<>*tech*", Operator:=xlAnd, Criteria2:="<>*qa*"
Please change this line, and try.
 
Upvote 0
Hi

Try :-
Code:
Dim DesCol As Long, LastRow As Long ' Always define rows and columns as Long
Dim DesRng As Range

'Cells(3, 1).Select ' you do not need to select cells

'Do While ActiveCell <> "Description"
'ActiveCell.Offset(0, 1).Select
'Loop
DesCol = Application.WorksheetFunction.Match("Description", [A3:CZ3], 0) ' Alternative method of finding a column header


LastRow = Cells(Rows.Count, DesCol).End(xlUp).Row
Set DesRng = Range(Cells(3, 1), Cells(LastRow, DesCol))

  DesRng.AutoFilter ' reset any filters already on the sheet
  DesRng.AutoFilter Field:=DesCol, Criteria1:="<>*tech*", Operator:=xlAnd, Criteria2:="<>*qa*"

hth
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
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