Help With Code To Colour Cells

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I was given the code below so that when I enter the letters anywhere on the worksheet it colours them in. I have changed the spreadsheet around so it is running vertical rather than horizontally, but it doesn't work now and I thought it should make no difference! Help please!

The range now would be C4:CB316

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim intclr As Integer
If Application.Intersect(Range("A1"), Range("h15")) Is Nothing Then
If Target.count > 1 Then Exit Sub
Select Case Target
Case "T"
intclr = 40
Case "Y"
intclr = 36
Case "C"
intclr = 35
Case "S1" To "S8"
intclr = 37
Case "O" To "o"
intclr = 43
Case "L1" To "L8"
intclr = 42
Case Else
End Select
Target.Interior.ColorIndex = intclr
End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim intclr As Integer
    
    If Target.Count > 1 Then Exit Sub
    
    If Not Intersect(Target, Range("C4:CB316")) Is Nothing Then
        
        Select Case Target
            Case "T": intclr = 40
            Case "Y": intclr = 36
            Case "C": intclr = 35
            Case "S1" To "S8": intclr = 37
            Case "O" To "o": intclr = 43
            Case "L1" To "L8": intclr = 42
            Case Else
        End Select
        
        Target.Interior.ColorIndex = intclr
        
    End If
    
End Sub
 
Upvote 0
Thanks works great. Can it be amended slightly so that should I have to delete whatever is in the cell it will take the colour out please.
 
Upvote 0
Well if I accidentally enter in a cell and need to delete it the cell remains the colour according to what was typed in there. Can it go back to no colour once I delete?
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim intclr As Integer
    
    If Target.Count > 1 Then Exit Sub
    
    If Not Intersect(Target, Range("C4:CB316")) Is Nothing Then
        
        Select Case Target
            Case "T": intclr = 40
            Case "Y": intclr = 36
            Case "C": intclr = 35
            Case "S1" To "S8": intclr = 37
            Case "O" To "o": intclr = 43
            Case "L1" To "L8": intclr = 42
            Case "" : intclr =  xlNone
            Case Else
        End Select
        
        Target.Interior.ColorIndex = intclr
        
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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