+ Reply to Thread
Results 1 to 2 of 2

Thread: How can I create a list of data by cell color?

  1. #1
    Registered User
    Join Date
    01-10-2012
    Location
    Greensboro, NC
    MS-Off Ver
    Excel 2007
    Posts
    1

    How can I create a list of data by cell color?

    I have a worksheet with information separated by cell color. I want to pull the data from cells of a certain color, without manually going down the list and "copy-pasting". I know I can sort by cell color, but I want something that will automatically populate with data of a certain color. I don't want to change the order of the raw data by keeping all the same colors together.

    What I'm not trying to do: Change the cell color of data that meets my criteria. I know this is easily done with Conditional formatting.
    What I am trying to do: Get a list of data that is already a certain cell color.

    I've uploaded a simplified file to help explain. In it, there are 3 sets of data (Site 1, Site 2, Site 3). I want to create a list of the data in green cells, which happens to be all of Site 1 and Site 3.

    I don't know if this can be accomplished with any built in functions, or if it will require some type of script or macro?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Guru Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007
    Posts
    3,523

    Re: How can I create a list of data by cell color?

    See attached.

    Basic code - no error handling and set to use ONLY the shade of green you have used - will fail on any other shade of green.

    It would best if you estalish a specific criteria for determining when a cell gets a green color and then use this same criteria in VBA.

    Option Explicit
    
    Sub Get_Cells_By_Color()
    
        Dim lastrow As Long, lastcol As Long
        Dim c As Range
        
        lastrow = Cells(Rows.Count, "B").End(xlUp).Row
        lastcol = Cells(4, Columns.Count).End(xlToLeft).Column
        
        Application.ScreenUpdating = False
        
        '// Sheet references are sheet code name - change them as required
        '// cell ranges may need to be adjusted
        
        With Sheet1
            For Each c In .Range("A4", .Cells(lastrow, lastcol))
                If c.Interior.Color = 5296274 Then
                    .Cells(c.Row, "E").Value = "green"
                End If
            Next c
            .AutoFilterMode = False
            .Range("E3:E" & lastrow).AutoFilter field:=1, Criteria1:="green"
            .Range("A3:C" & lastrow).SpecialCells(xlCellTypeVisible).Copy Sheet2.Range("A1")
            .AutoFilterMode = False
            .Range("E4:E" & lastrow).ClearContents
        End With
        
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    
    End Sub
    There macro is assigned to a button on the sheet and the results are copied to sheet2.

    Get Green Cells.xlsm
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

+ 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