automatically change tab color

Sammi8796

Board Regular
Joined
Dec 12, 2007
Messages
100
Office Version
  1. 2016
Platform
  1. Windows
Can anyone tell me if it's possible to change the tab color based on a formula in a cell on each tab? I want to change the tab color to red if the number in A1 is a negative number. If it's a positive number I just want it to remain the same, the default color. I have many tabs in the workbook and I'm using excell 2003. Thanks in advance.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
put this into the "ThisWorkbook" section
Code:
Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)
    With Application
        .Calculation = xlCalculationManual
        .DisplayAlerts = False
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    Dim sh As Worksheet
    For Each sh In ActiveWorkbook
        If sh.Range("a1") < 0 Then
            sh.Tab.ColorIndex = 30
        Else
            sh.Tab.ColorIndex = -4142
        End If
    Next
    With Application
        .Calculation = xlCalculationManual
        .DisplayAlerts = True
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub
 
Upvote 0
I'm so bad at VBA. I have a really hard time trying to figure out how to make it work. Can you give me a step by step or is that asking too much? Any more specific help you can give me would be appreciated so much.
 
Upvote 0
hit Alt+F11
on the left side, double click on "ThisWorkbook"
Paste that code in there

You're done. Everytime you enter something into a cell, it will do a check on each sheet in your workbook. If it's negative, the sheet will be Red. if it isn't, it'll turn it back to Grey.
 
Upvote 0
when i hit alt+f11 a white vba box come up with two drop downs at the top. One on the left says "general" and the other on the right says "declarations." is this where Im supposed to paste it? If so, when I do, do i hit save or just close the window? If this is correct, I did it and nothing happens. Can you help me along? I'm sorry I'm just so lost with this stuff. I've never worked with macros or vba.
 
Upvote 0
Ok, i did that. Do I just close the window or is there something I'm supposed to click because it didn't work. I hit save and closed the vba window and I didn't see any tab turn color.
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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