• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Change Cell Background

I need to change one cells background color depending on if there is data in other cell. See example.
 

Attachments

  • Change background color depending on another cell.xlsx
    9.2 KB · Views: 7
Code:
Sub TurnsRed()
    Dim c As Range
    Dim rng As Range
    Dim cRow As Long
    Set rng = Range("E5:G8")
    For Each c In rng
        If c = "" Then
            cRow = c.Row
            Range("C" & cRow).Interior.ColorIndex = 3
        End If
    Next c
End Sub

Standard Module
How to install your new code
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Press Alt+F11 to open the Visual Basic Editor
Choose Insert > Module
Edit > Paste the macro into the module that appeared
Close the VBEditor
Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

To run the Excel VBA code:
Press Alt-F8 to open the macro list
Select a macro in the list
Click the Run button
 
Back
Top