Change Tab color based on tab name

carura

New Member
Joined
Sep 20, 2011
Messages
25
Hi All,

Im working on a worksheet for multiple evaluation forms.
I have 3 types of forms:
OTO
TRNG
RTR

I need a code or something to make the tab/sheet colors change once the type of form is declared on the tab name.

Example:

If I put "OTO Nov 17" as the tab name, it will change the tab color to blue
or if I put "RTR Nov 5" as the name it will change to green.

I usually put the evaluation type as the first word then the date the evaluation was done.

Any help would be appreciated.

Thanks in advance! :):):)
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Here’s a take on this.

I could not find an event that is raised on renaming a sheet, so I put it in SheetActivate. This means that when the sheet is activated, the color change wil occur. I don't think the difference is noticeable.

Put this in the “ThisWorkbook” in the VBA Project window
· open the application (use a test application at first)
· press F11
· Double Click ThisWorkBook on the left hand side
· Copy the code and paste it into the Right Hand Side
· Save

Option Explicit
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.ScreenUpdating = False
Select Case Left(ActiveSheet.Name, 3)
Case "OTO"
Application.ActiveSheet.Cells.Interior.ColorIndex = 37
makegrid
Case "RTR"
Application.ActiveSheet.Cells.Interior.ColorIndex = 35
makegrid
Case "TRN"
End Select
Application.ScreenUpdating = True
End Sub

Sub makegrid()
With Application.ActiveSheet.Cells.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Application.ActiveSheet.Cells.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
 
Upvote 0
Hi All,

Im working on a worksheet for multiple evaluation forms.
I have 3 types of forms:
OTO
TRNG
RTR

I need a code or something to make the tab/sheet colors change once the type of form is declared on the tab name.

Example:

If I put "OTO Nov 17" as the tab name, it will change the tab color to blue
or if I put "RTR Nov 5" as the name it will change to green.

I usually put the evaluation type as the first word then the date the evaluation was done.

Any help would be appreciated.

Thanks in advance! :):):)

Maybe:

Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

With ActiveSheet

    If Left(ActiveSheet.Name, 3) = "OTO" Then
    
        .Tab.ColorIndex = 4
        
    ElseIf Left(ActiveSheet.Name, 3) = "RTR" Then
    
        .Tab.ColorIndex = 33
        
    Else
    
        .Tab.ColorIndex = xlNone
        
    End If
    
End With
End Sub

Change the colors too your preferred shading.
 
Upvote 0
Hi John Davis!

You reply was what I was looking for.
It changes the color of the tab but it only worked for the condition
it doesnt recognize the second condition.

I mean, all forms with OTO changed in color, so it worked.
But the forms with RTR didnt change.:eek::(

@tlowry
Thanks for trying, but your code changes the color of the whole sheet.
I only need the tab color to change. :)
 
Upvote 0
Hi John Davis!

You reply was what I was looking for.
It changes the color of the tab but it only worked for the condition
it doesnt recognize the second condition.

I mean, all forms with OTO changed in color, so it worked.
But the forms with RTR didnt change.:eek::(

@tlowry
Thanks for trying, but your code changes the color of the whole sheet.
I only need the tab color to change. :)

It worked when I tested it. Did you place the code in the specified Workbook change event?
 
Upvote 0
Hey John,

I tried it again. It works! :biggrin:
I guess I had to click on cells on the sheet to make it work.
I thought it would automatically change every tab.

Thanks a lot!!:biggrin::biggrin:
 
Upvote 0

Forum statistics

Threads
1,216,473
Messages
6,130,838
Members
449,597
Latest member
buikhanhsang

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