If/Then formula to change cell color

tinkerbell737

Board Regular
Joined
Nov 25, 2002
Messages
96
I want to know if it's possible to use an If/Then formula to change a cell's color? Even changing the text color would be cool.

I have two worksheets in the same spreadsheet. The first one is a complete list of names and the second is a list of names in a particular group.

I want to say IF this person belongs to the group on worksheet2, then highlight the cell with their name on worksheet1.

Can this be done?

ALTERNATELY, I would be happy with a remark in another column that indicates that the person is part of the group.
 
This will, for all cells in a given numerical range, color red any cell that is not blank.

Adjust variables/objects/conditinals as you need.

Code:
Sub ScanAndColor() 'by Combat Volcano
    For x = 1 To 100 ' x range, can be "40 to 41" etc
        For y = 1 To 100 ' y limit same deal
            If Sheets("Sheet1").Cells(x, y).Value <> "" Then
                Sheets("Sheet1").Cells(x, y).Interior.Pattern = xlSolid
                Sheets("Sheet1").Cells(x, y).Interior.PatternColorIndex = xlAutomatic
                Sheets("Sheet1").Cells(x, y).Interior.Color = 255
            End If
        Next y
    Next x
End Sub
 
Last edited:
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
New and improved... still larnin mah veebee

Code:
Sub ScanAndColor()
    For x = 1 To 100 ' x limit
        For y = 1 To 100 ' y limit
            If Sheets("Sheet1").Cells(x, y).Value <> "" Then
                With Sheets("Sheet1").Cells(x, y)
                    .Interior.Pattern = xlSolid
                    .Interior.PatternColorIndex = xlAutomatic
                    .Interior.Color = 255
                End With
            End If
        Next y
    Next x
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,939
Members
449,094
Latest member
teemeren

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