What is the Usage of sheet color in Excel?
When we prepare a report or a dashboard it is easy to identify or analyze reports with a change of color sheet tabs. Analysts generally give the same color to the tabs which are related to same function.
For example if you are preparing a dashboard for all the departments in an organization. All the worksheet tabs related finance can be highlighted in red, HR can be in Blue, etc. so with this report looks good and is easy to understand.
How to use VBA Code to Color Excel Worksheet or tab?
This Example will show you how to change the Color of Sheet tabs using Excel VBA. In the following Example we are changing the Sheet2 tabs color to Red. Lets have a look
VBA Code To Change Tab Color
Sub redColorSheetTab() Sheets("Sheet2").Tab.ColorIndex = 3 '3=Red, 4=green, 5=blue,6=yellow etc. End Sub
Steps to use this VBA Code
- Open an excel workbook
- Press Alt+F11 to open VBA Editor
- Insert a new module from Insert menu
- Copy the above code and Paste in the code window
- Save the file as macro enabled workbook
- Press F5 to see the output
- You can see the Sheet2 tab in Red color
Another method to Change Tab Color using Excel VBA
Here is another help code for programmers to change the color of Excel sheet tab. I have shown another way to achieve this:
- Using standard colors like Green, Blue, Red, White etc.
Change the Color of Sheet Tabs in Excel VBA – Example
- Using RGB (Red, Green Blue) function to set a specific color
'This function changes the tab color of a sheet
'Option 1 - using standard colors vbGreen, vbRed, vbBlack, vbYellow, vbBlue, vbWhite etc.
Sheet1.Tab.Color = vbGreen
'Option 2 - using RGB colors
Sheet1.Tab.Color = RGB(117, 117, 117)
You may have noticed that in Option 2, I have used RGB function to change the sheet tab color. You may read this post to know more about how to get RGB codes of a color.
Other Examples of Coloring Excel Tabs using VBA
VBA Code To Color The ActiveSheet
If you need to change the color of the tab you are currently viewing, you can use the following VBA macro code along with your desired RGB color code:
Sub ChangeTabColor() 'Objective: Change Selected Tab To Specific Color ActiveSheet.Tab.Color = RGB(25, 25, 25) End Sub
VBA Code To Remove Color From All Sheets
If you need to write a VBA loop to ensure all worksheet tabs have their color removed, you can use a macro similar to the below code:
Sub ClearAllTabColor() 'PURPOSE: Remove Tab Color from all Sheets Dim sht As Worksheet For Each sht In ActiveWorkbook.Worksheets sht.Tab.Color = xlNone Next sht End Sub
Download Practice File for Free
To help you practice this code, we have made this code available through practice file. Click on the below link to download the practice file.
Some other VBA Codes which might be Helpful
Excel VBA Course : Beginners to Advanced
We are currently offering our Excel VBA Course at discounted price. This courses includes On Demand Videos, Practice Assignments, Q&A Support from our Experts. Also after successfully completion of the certification, will share the success with Certificate of Completion
This course is going to help you to excel your skills in Excel VBA with our real time case studies.
Lets get connected and start learning now. Click here to Enroll.
Secrets of Excel Data Visualization: Beginners to Advanced Course
Here is another best rated Excel Charts and Graph Course from excelsirji. This courses also includes On Demand Videos, Practice Assignments, Q&A Support from our Experts.
This Course will enable you to become Excel Data Visualization Expert as it consists many charts preparation method which you will not find over the internet.
So Enroll now to become expert in Excel Data Visualization. Click here to Enroll.
Use Automated Excel Utility Tools to increase productivity
Hope you are enjoying learning Excel with us, if you want any support related to this article, please do comment else you can ask questions in Excel Community