VBA code for picking cells by color

TCHME

New Member
Joined
Oct 30, 2010
Messages
10
I have a spread sheet with cells that are color coded with info.
I would like to write a code that would let me look for a color in my workbook
Is there a way to do this
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi TCHME,

You can start running the 2 following macros in given order:

Code:
Sub Coloring_Cells()
   For i = 1 To 6
      Cells(i + 2, 2).Interior.ColorIndex = i
   Next
End Sub
--------------------------------------------------------------
Sub Look_Color()

Dim strColor As String

    strColor = InputBox(Prompt:="Color you want to looking for?", _
          Title:="COLOR TO SEARCH", Default:="No color")

        If strColor = "No color" Or strColor = vbNullString Then
        Exit Sub
        
        Else
          Select Case strColor
            Case "Black", "black", "BLACK"
                Application.FindFormat.Interior.ColorIndex = 1
                Cells.Find(What:="", after:=[A1], SearchFormat:=True).Activate
            Case "White", "white", "WHITE"
                Application.FindFormat.Interior.ColorIndex = 2
                Cells.Find(What:="", after:=[A1], SearchFormat:=True).Activate
            Case "Red", "red", "RED"
                Application.FindFormat.Interior.ColorIndex = 3
                Cells.Find(What:="", after:=[A1], SearchFormat:=True).Activate
            Case "Green", "green", "GREEN"
                Application.FindFormat.Interior.ColorIndex = 4
                Cells.Find(What:="", after:=[A1], SearchFormat:=True).Activate
            Case "Blue", "blue", "BLUE"
                Application.FindFormat.Interior.ColorIndex = 5
                Cells.Find(What:="", after:=[A1], SearchFormat:=True).Activate
            Case "Yellow", "yellow", "YELLOW"
                Application.FindFormat.Interior.ColorIndex = 6
                Cells.Find(What:="", after:=[A1], SearchFormat:=True).Activate
            Case Else
                Exit Sub
          End Select

        End If
End Sub
Hope this helps.

Regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
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