VBA Conditinal Formatting in multiple columns

seasidematt

Board Regular
Joined
Jun 18, 2009
Messages
69
I'm being really thick and cannot seem to get this to work but i looking at putting multiple VBA conditianl Formmating into one worksheet but cannot get it to work

In Coulmn A i have
Code:
Private Sub CellA(ByVal Target As Range)
 
If Target.Count > 1 Then Exit Sub
 
If Intersect(Target, Range("a3:a500")) Is Nothing Then Exit Sub
 
Select Case Target.Value

Case Is = ""
    Target.Interior.ColorIndex = 0

Case Is = "Em"
    Target.Interior.ColorIndex = 43
 
Case Is = "Ex"
    Target.Interior.ColorIndex = 44
    
Case Is = "Fst"
    Target.Interior.ColorIndex = 45
    
Case Is = "PDF"
    Target.Interior.ColorIndex = 50

Case Is = "SCS"
    Target.Interior.ColorIndex = 36
    
Case Is = "Oth"
    Target.Interior.ColorIndex = 44
  
End Select

End Sub
And then in column H i want this code
Code:
Private Sub CellH(ByVal Target As Range)
 
If Target.Count > 1 Then Exit Sub


If Intersect(Target, Range("h3:h500")) Is Nothing Then Exit Sub
 
Select Case Target.Value

Case Is = ""
    Target.Interior.ColorIndex = 0

Case Is = "R"
    Target.Interior.ColorIndex = 3
 
Case Is = "A"
    Target.Interior.ColorIndex = 45
    
Case Is = "G"
    Target.Interior.ColorIndex = 4
    
Case Is = "C"
    Target.Interior.ColorIndex = 33
  
End Select
 
End Sub
How do i combine them so they both work on teh same worksheet... I cannot fathom it out!

Thanks for yoru help
Matt
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Perhaps like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
 
If Not Intersect(Target, Range("a3:a500")) Is Nothing Then
 
    Select Case Target.Value
    
    Case Is = ""
        Target.Interior.ColorIndex = 0
    
    Case Is = "Em"
        Target.Interior.ColorIndex = 43
     
    Case Is = "Ex"
        Target.Interior.ColorIndex = 44
        
    Case Is = "Fst"
        Target.Interior.ColorIndex = 45
        
    Case Is = "PDF"
        Target.Interior.ColorIndex = 50
    
    Case Is = "SCS"
        Target.Interior.ColorIndex = 36
        
    Case Is = "Oth"
        Target.Interior.ColorIndex = 44
      
    End Select
ElseIf Not Intersect(Target, Range("h3:h500")) Is Nothing Then
 
    Select Case Target.Value
    
    Case Is = ""
        Target.Interior.ColorIndex = 0
    
    Case Is = "R"
        Target.Interior.ColorIndex = 3
     
    Case Is = "A"
        Target.Interior.ColorIndex = 45
        
    Case Is = "G"
        Target.Interior.ColorIndex = 4
        
    Case Is = "C"
        Target.Interior.ColorIndex = 33
      
    End Select
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,920
Latest member
jaspers

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