Select by Interior Color

Ritt

New Member
Joined
Oct 29, 2010
Messages
47
In VBA how can I select a range of cells that have the same Interior color that is in like cell A1 in a range of cells B3:I18. Thanks for all your help.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hello

Try this, on a COPY of your data.

<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN><br><SPAN style="color:#00007F">Sub</SPAN> test()<br>**<SPAN style="color:#00007F">Dim</SPAN> colour <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Integer</SPAN>, Frng <SPAN style="color:#00007F">As</SPAN> Range, Srng <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, cel <SPAN style="color:#00007F">As</SPAN> Range<br>**colour = Range("A1").Interior.Color<SPAN style="color:#00007F">In</SPAN>dex<br>**<SPAN style="color:#00007F">Set</SPAN> Frng = Range("B3:I18")<br>**Srng = ""<br>**<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cel In Frng<br>****<SPAN style="color:#00007F">If</SPAN> cel.Interior.ColorIndex = colour <SPAN style="color:#00007F">Then</SPAN> Srng = Srng + cel.Address & ","<br>**<SPAN style="color:#00007F">Next</SPAN> cel<br>****<SPAN style="color:#00007F">If</SPAN> Srng <> "" <SPAN style="color:#00007F">Then</SPAN><br>******Srng = Left(Srng, Len(Srng) - 1)<br>******Range(Srng).Select<br>****<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
Adapted from this link.

http://forums.techguy.org/business-applications/505523-excel-macro-selecting-multiple-cells.html
 
Last edited:
Upvote 0
Code:
Option Explicit
Sub SameColorSelection()
    Dim MyClr As Long
    Dim MyClrs As Range
    Dim MyCells As Range
    MyClr = Range("A1").Interior.Color
    For Each MyCells In Range("B3:I18")
        If MyCells.Interior.Color = MyClr Then
            If MyClrs Is Nothing Then
                Set MyClrs = MyCells
            Else
                Set MyClrs = Union(MyClrs, MyCells)
            End If
        End If
    Next
    If MyClrs Is Nothing Then
        MsgBox "No Color Match"
    Else
        MyClrs.Select
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

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