filter cells by text font color

orit

New Member
Joined
Oct 31, 2004
Messages
44
I have a large worksheet which I would like to filter according the color of the font of the text written in each cell. I want that by clicking a button, only the rows where the color of the text in specific column is blue will be displayed, by clicking another button, only the rows with the red text will be displayed etc..., how suppose to be macro for that?

Thanks a lot
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Harvey

Well-known Member
Joined
Nov 18, 2004
Messages
953
something like:
Code:
For Each cell In Range("A1:B10")

  If cell.Font.ColorIndex = 2 Then

    cell.EntireRow.Hidden = True
    
  End If

Next cell
this will hide the rows in which the colored text appears.
 

orit

New Member
Joined
Oct 31, 2004
Messages
44
Thanks much,

I have various font colors in the worksheet... If possible, is there a way to define which color to show (instead of which color to hide)?
if not, what is the syntax for hiding multiple colors?

another thing, is it possible that it will work on all the content of the sheet instead of defining a range?

Thanks again
 

Harvey

Well-known Member
Joined
Nov 18, 2004
Messages
953
Code:
For Each cell In Range("A1:B10")

  If cell.Font.ColorIndex <> mycolor Then

    cell.EntireRow.Hidden = True
   
  Else

    cell.EntireRow.Hidden = False

  End If

Next cell

where my color is the color you want to show.
I added some code to make hidden rows visible again, because you might want to run this code multiple times in a row I think.
 

orit

New Member
Joined
Oct 31, 2004
Messages
44

ADVERTISEMENT

Thanks a lot,

Somehow, it hides all the specified range. any idea why?

Thanks
 

orit

New Member
Joined
Oct 31, 2004
Messages
44

ADVERTISEMENT

with a number, e.g. 3

What should it be?

Thanks
 

Harvey

Well-known Member
Joined
Nov 18, 2004
Messages
953
does the number correspond with the color that you want to make visible? You can see this by using this code:

Code:
Sub x()
    MsgBox (Range("A1").Font.ColorIndex)
End Sub

and pressing F5
 

Harvey

Well-known Member
Joined
Nov 18, 2004
Messages
953
sorry, the range I used is not correct. It would look for both the cells in column a an b to have the right color. change it to this:
Code:
For Each cell In Range("A1:A10")

  If cell.Font.ColorIndex <> mycolor Then

    cell.EntireRow.Hidden = True
   
  Else

    cell.EntireRow.Hidden = False

  End If

Next cell
 

Forum statistics

Threads
1,148,272
Messages
5,745,791
Members
423,973
Latest member
man_this_is_hard

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