How would i select all cells with the same fill colour?

sl1990

New Member
Joined
Jun 3, 2011
Messages
20
Hi how would i select all cells with the same fill colour? im using excel 2004 on a mac (it has VBA). is there a macro that could do this ?

cheers
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi There,

This should work for you. Change the range and color as required:

Code:
Sub Macro2()

    Dim myString as string
    Dim mySelection as string

    For Each cell In Range("A1:A17")
    
        If cell.Interior.Color = vbRed Then
            myString = myString & cell.Address & ","
        End If
    
    Next cell
    
    mySelection = Left(myString, Len(myString) - 1)
    
    Range(mySelection).Select

End Sub
There may be a more elegant way of doing this than using string concatenation for the range, but it works fine.

I tested this on a PC with Excel 2003 not a Mac but it should be OK
 
Upvote 0
thanks for that dfenton21 but im getting a slight problem with it, i get a runtime error 5, invalid procedure call or argument. for this part of the macro

"mySelection = Left(myString, Len(myString) - 1)"

any ideas ?

cheers
 
Upvote 0
I dont know if you can do this in 2004, but there is a find format feature in Find/Replace where you can select a cell format and then find all. Then highlight all inthe box that is displayed at the bottom of find/replace.
 
Upvote 0
It is working for me perfectly, so it may be an issue with Excel 2004 on a Mac. Sorry I don't have any experience with that, so I'm unsure.

Take a look at the left and len functions so see if the syntax is correct for your version. They are very simple string functions, so I can't foresee any problems.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,733
Members
452,939
Latest member
WCrawford

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