+ Reply to Thread
Results 1 to 5 of 5

Macro that will check a cell color

Hybrid View

  1. #1
    Registered User
    Join Date
    10-01-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Macro that will check a cell color

    I need to make a macro that will check the color of a cell in say column "D" and if it is yellow then change the value that is in column "C" of the same row. I have never written a macro before, but the project I am working on has about a 1000 rows and several hundred cells that are highlighted yellow that need to say rev2 on the corrisponding line.

    any input would be greatly appriciated.

    thank's in advance.

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

    Re: Macro that will check a cell color

    This assumes "yellow" is the standard yellow (color index number 6)
    Option Explicit
    
    Sub Change_Value_By_Color()
    
        'declare variables
        Dim c As Range, lrow As Long
        
        'count the number of used rows in column-D
        lrow = Cells(Rows.Count, "D").End(xlUp).Row
            
        On Error Resume Next
        
        'loop thru cells in column-D and test if colorindex = 6 (standard yellow)
        For Each c In Range("D1:D" & lrow)
        
            If c.Interior.ColorIndex = 6 Then
            
                'offset to cell in same row but in column-C and place value into cell
                c.Offset(, -1).Value = "rev2"
                
            End If
        Next c
    
    End Sub
    Last edited by Palmetto; 10-02-2009 at 07:28 AM.

  3. #3
    Registered User
    Join Date
    10-01-2009
    Location
    San Diego, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macro that will check a cell color

    palmetto,

    you are so awesome, i can't wait to get to work in the morning and try it out. you just turned an all day job into like 20 minutes. I'm really gonna have to learn how to do these macros.

    In your leisure, do you think you can explain what you did so I can learn from it. I understand the if statment, but not some of the designations such as: lrow = Cells(Rows.Count, "D").End(xlUp).Row


    thanks again

  4. #4
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Macro that will check a cell color

    You can use excell 2007 for filtering on colors. Also please find the attachment where I have used the custom function getcolor to find the color of a cell. you can find the color of the font also by adding an f in the arguments
    Attached Files Attached Files

  5. #5
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Macro that will check a cell color

    In your leisure, do you think you can explain what you did so I can learn from it. I understand the if statment, but not some of the designations such as: lrow = Cells(Rows.Count, "D").End(xlUp).Row
    Previous post amended with comments to the code.

+ 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.6.0 RC 1