Excel VBA tab colour automatically changes - controlled by if statement

justlearning1

New Member
Joined
Apr 7, 2014
Messages
2
I am completely new to VBA excel. I would like to change the tab colour in a workbook based on the results of an if statement in A1

Here is what I currently have based on code I got from this site. I have no idea what to change in this code so that it responds to an if statement rather than something that was typed in the cell. Thanks!


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range) If Not Intersect(Target, Sh.Range("G44")) Is Nothing Then Select Case UCase(Target.Value) Case Is = "LOW" Sh.Tab.ColorIndex = 10 Case Is = "MED" Sh.Tab.ColorIndex = 6 Case Is = "HIGH" Sh.Tab.ColorIndex = 3 Case Else Sh.Tab.ColorIndex = -4142 End Select End If End Sub</pre>
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try

Code:
Private Sub Workbook_SheetCalculate(ByVal Sh As Object)
Select Case UCase(Sh.Range("G44").Value)
    Case "LOW": Sh.Tab.ColorIndex = 10
    Case "MED": Sh.Tab.ColorIndex = 6
    Case "HIGH": Sh.Tab.ColorIndex = 3
    Case Else: Sh.Tab.ColorIndex = -4142
End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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