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:

Takae

Well-known Member
Joined
Jul 1, 2015
Messages
674
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.
 

ukmikeb

Well-known Member
Joined
Jul 10, 2009
Messages
2,756
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
 

Forum statistics

Threads
1,081,989
Messages
5,362,581
Members
400,683
Latest member
LogChief

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top