+ Reply to Thread
Results 1 to 3 of 3

Thread: Search cell with specify ColorIndex

  1. #1
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Search cell with specify ColorIndex

    Range SearchRng is a predefined range that I have!

    If I want to search SearchRng for text "Test" then I would use this code

    Set rFind = SearchRng.Find("Test", LookIn:=xlValues, Lookat:=xlWhole, _
    SearchOrder:=xlNext, MatchByte:=True)
    However, instead of "Test", I want to find Cell with Interior.ColorIndex = 4

    Would you help please!?

    Thank you,

    NTB
    Last edited by NTB; 08-18-2011 at 02:52 PM.

  2. #2
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Search cell with specify ColorIndex

    Hi NTB, if you want to find a cell with a particular interior colour, than I would go with something like
    Sub NTB()
        Dim rFind As Range, SearchRng As Range
        Dim ws As Worksheet
        Set ws = Worksheets("Sheet1")
        
        Set SearchRng = ws.Range("A2:D5")
        
        For Each rFind In SearchRng
            If rFind.Interior.ColorIndex = 4 Then
                MsgBox "Green found in range " & rFind.Address
            End If
        Next rFind
    End Sub
    You will have to substitute the range I used with yours and then add what you want to do to the cells once you find them though. Let me know if this helps.
    Please leave a message after the beep!

  3. #3
    Registered User
    Join Date
    10-01-2009
    Location
    Manassas, VA
    MS-Off Ver
    Excel 2007
    Posts
    86

    Re: Search cell with specify ColorIndex

    Mordred: That is exactly what I currently have. Somehow I thought it is insufficient, so I was hoping for some faster find. Let's see if we have another method - if not I will close SOLVED this thread.

    Thank you once again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0