Maybe Select Case

Titian

Well-known Member
Joined
Dec 17, 2004
Messages
567
I have a simple means of highlighting each changed cell in a worksheet:-

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Each time a cell is changed the FILL & FONT colours are automatically 
' changed as per following settings

    Target.Font.ColorIndex = 1
    ' 1-Black, 2-White
    
    Target.Interior.ColorIndex = 6
    ' 3-Red, 4-Green, 5-Dk Blue, 6-Yellow
End Sub

What I would like to do is to have the code recognise which COLUMN is being changed and to apply a different set of Font & Fill colours accordingly, maybe via a CASE statement.

Your help is appreciated.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iCol As Long, fCol As Long
Select Case Target.Column
    Case 1: fCol = 1: iCol = 3
    Case 2: fCol = 2: iCol = 4
    Case Else: fCol = 1: iCol = 5
End Select
' Each time a cell is changed the FILL & FONT colours are automatically
' changed as per following settings

    Target.Font.ColorIndex = fCol
    ' 1-Black, 2-White
    
    Target.Interior.ColorIndex = iCol
    ' 3-Red, 4-Green, 5-Dk Blue, 6-Yellow
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,947
Latest member
Gerry_F

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