VBA Code For Changing Tab Color Based On Cell Values In Drop Down List

systemsrool

New Member
Joined
Nov 5, 2015
Messages
14
I am trying to change the color of a tab based on the cell value in B5. B5 is a drop down list using data validation that contains four entries: "Flow Rack" , "Workstation" , "Machine Guarding" , and "Other (custom)". A tab is named after each one of these as well. If someone selects "Workstation" from the drop down menu then I would like the "Workstation" tab to turn green. If any of the other three options are selected I want the "Workstation" tab to be red.

Any help is much appreciated. I only have very little experience with coding.
 
How do I do this for the three other tabs as well. If there are four options in the drop down and four corresponding tabs. I want the same function for each one.
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
I got it. I was right clicking the "Workstation" tab and doing all of this.. didn't know I was supposed to put in the code for the first tab.
 
Upvote 0
Not sure if you saw my last reply, but how do I do this for the three other tabs as well. If there are four options in the drop down and four corresponding tabs. I want the same function for each one. I figure I could copy the code three more times, but I don't know what to change in it.

Thanks for your responses. Sorry for troubling you again.
 
Upvote 0
Not sure what your wanting now. Your original post said:
I would like the "Workstation" tab to turn green. If any of the other three options are selected I want the "Workstation" tab to be red.

Now it sounds like you want the tab to turn Green if any of these four choices are chosen is that true?
 
Upvote 0
I was using that as an example.
There are 4 options in a drop down menu... and 4 tabs corresponding with each option.
When option 1 is picked, tab 1 is green otherwise it is red.
When option 2 is picked, tab 2 is green otherwise it is red.
When option 3 is picked, tab 3 is green otherwise it is red.
When option 4 is picked, tab 4 is green otherwise it is red.

1 = Flow Rack 2 = Workstation 3 = Machine Guarding 4 = Other (custom)
 
Upvote 0
Maybe someone else here on Mr. Excel can help you. This is now getting more complicated.
Which ever choice you make you want that tab turning Green and the other three to turn Red.
Without knowing if this is all the tabs in your workbook it makes this task very difficult for me.
It would involve a whole lot of If Else statements.
 
Last edited:
Upvote 0
This script will set every worksheet tab in your workbook "Red" except for the one selected in your drop down list and that one will be green.
Code:
Sub Tab_Colors()
Dim i As Integer

    For i = 1 To Sheets.Count
    Sheets(i).Tab.ColorIndex = 3
    Next
    Sheets(Cells(5, 2).Value).Tab.ColorIndex = 4
End Sub
 
Last edited:
Upvote 0
83cccdc8af.png


Maybe this will clear things up. I don't want customer info to change color. I was using the numbers 1-4 to help you understand. But, yes whatever option in the drop down is selected should be a green tab while the others should be red. Customer info doesn't change at all. Is this possible?
 
Upvote 0
Assuming the Customer Info sheet is in the far left position on the tab menu. This script should work:
Code:
Sub Tab_Colors()
Dim i As Integer

    For i = 2 To Sheets.Count
    Sheets(i).Tab.ColorIndex = 3
    Next
    Sheets(Cells(5, 2).Value).Tab.ColorIndex = 4
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,394
Members
449,155
Latest member
ravioli44

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