Hi anyone,
How could I write a VB code that would filter rows of column O that is highlighted in yellow?
My data starts from row 9 where headers in row 8.
Any help on this would be kindly appreciated.
Thanks in advance.
Filter by colour
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Filter by colour
You can adapt this to suite...
Code: Select all
Sub FilterData()
Dim rgData As Range
Const sCriteria = "Test" '<< Change the criteria to filter for...
Set rgData = Range(Cells(8, "O"),Cells(Rows.Count, "O").End(xlUp))
rgData.AutoFilter 1, sCriteria
'rgData.Parent.AutoFilterMode = False '<< Remove filter if needed...
End Sub
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78790
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Filter by colour
To filter by color:
Code: Select all
Sub FilterData()
Dim rng As Range
Dim m As Long
m = Range("O" & Rows.Count).End(xlUp).Row
Set rng = Range("O8:O" & m)
rng.AutoFilter Field:=1, Criteria1:=vbYellow, Operator:=xlFilterCellColor
End Sub
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Filter by colour
Arghhh!!!
Completely forgot about the part to filter by colour!
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- SilverLounger
- Posts: 2347
- Joined: 23 Feb 2010, 12:07
Re: Filter by colour
Thanks for the help Rudi & Hans. Since I also have data in columns C to column P I've changed the field line from Field:=1 to Field:=13 so that it would filter column O.
Best Regards,
Adam
Adam