VBA code to change tab colours based on cell with formula on each sheet (60 sheets)

dotpsn

New Member
Joined
Jan 11, 2023
Messages
6
Office Version
  1. 365
Platform
  1. Windows
As header says - I have searched and searched but nothing has worked. I have 0 knowledge of VBA as I am only just learning about it now (big struggles so hoping to find some help here :)).
I am hoping someone could possibly help get a script that will change the colour of each tab based on cell b4. Cell b4 will either say home or away (ideally green in this case) or be blank (colourless is fine).

Could someone PLEASE help??? :)

Ps I am often quite stubborn and refuse to ask questions - I would rather research and find a solution but this has me stumped!!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Maybe:
VBA Code:
Sub test()
    Dim ws As Worksheet
   
    For Each ws In Sheets
        If LCase(ws.Range("B4").Value) = "home" Then
            ws.Tab.ColorIndex = 10
        Else
            ws.Tab.ColorIndex = xlNone
        End If
    Next ws
End Sub
 
Upvote 0
Maybe:
VBA Code:
Sub test()
    Dim ws As Worksheet
  
    For Each ws In Sheets
        If LCase(ws.Range("B4").Value) = "home" Then
            ws.Tab.ColorIndex = 10
        Else
            ws.Tab.ColorIndex = xlNone
        End If
    Next ws
End Sub
Thanks - I assume this may not work if the cell contains "away"???
I will run it now and check though!!

Thanks
 
Upvote 0
Maybe:
VBA Code:
Sub test()
    Dim ws As Worksheet
  
    For Each ws In Sheets
        If LCase(ws.Range("B4").Value) = "home" Then
            ws.Tab.ColorIndex = 10
        Else
            ws.Tab.ColorIndex = xlNone
        End If
    Next ws
End Sub
WORKED!!!! But those 'away' tabs are still colourless. Could you please add away to show as red????
 
Upvote 0
Maybe:
VBA Code:
Sub test()
    Dim ws As Worksheet
  
    For Each ws In Sheets
        If LCase(ws.Range("B4").Value) = "home" Then
            ws.Tab.ColorIndex = 10
        ElseIf LCase(ws.Range("B4").Value) = "away" Then
            ws.Tab.ColorIndex = 3
        Else
            ws.Tab.ColorIndex = xlNone
        End If
    Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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