Change Worksheet tab color if worksheet contains text

mnty89

Board Regular
Joined
Apr 1, 2016
Messages
66
Hey everyone,

I can't figure this out..

Basically I have a workbook with several sheets. The macro runs and creates new sheets, so at the end I want to put in a small loop that will color code the worksheets that were just added..

I will have worksheets with DataAM, DataPM, DataMID, etc..

So I want to have the vba change the ones that contain "MID" to yellow, "AM" to red, and "PM" to green..

Anyone have any solutions?

Also with an error function built in if needed to where if the sheet is already the color, then skip it.
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi mnty,

This is indeed possible with VBA. Would you mind posting your VBA code so I can edit in the bit you require?

Thanks
Caleeco
 
Upvote 0
Here is the syntax.

Code:
Sub t()
Sheet1.Tab.Color = vbRed
End Sub
 
Upvote 0
Ok, I can write a standalone macro.

I assume the macro you currently have is naming the sheet also? Also your last requirement, error statement should never trigger (as new sheets are being created no?) Or are the sheets being copied from elsewhere.

Thanks
Caleeco
 
Upvote 0
Not sure why my response didnt post. I actually figured out a stupidly simple solution to just throw these at the end of the loops to do all I need.. Thanks guys for the responses!


Posting here in case someone googles later and needs the syntax

ActiveWorkbook.ActiveSheet.Tab.Color = vbGreen

ActiveWorkbook.ActiveSheet.Tab.Color = vbYellow

ActiveWorkbook.ActiveSheet.Tab.Color = vbRed
 
Upvote 0
Code:
Sub t()
If Sheets(DataAM).Tab.Color <> vbRed Then
 Sheets(DataAM).Tab.Color = vbRed
End If
If Sheets(DataPM).Tab.Color <> vbGreen Then
 Sheets(DataPM).Tab.Color = vbGreen
End If
If Sheets(DataMID).Tab.Color <> vbYellow Then
 Sheets(DataMID).Tab.Color = vbYellow
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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