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.
We can change the Worksheet tab colors by setting the Tab.ColorIndex property using Excel VBA.
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
Sub redColorSheetTab() Sheets("Sheet2").Tab.ColorIndex = 3 '3=Red, 4=green, 5=blue,6=yellow etc. End Sub
Here is another help code for programmers to change the color of Excel sheet tab. I have shown another way to achieve this:
'This function changes the tab color of a sheet
Sub ChangeSheetTabColor()
   '
   '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)
   '
End Sub
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.
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
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
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.
VBA Code to list Files in Folder To work on multiple files through VBA programming, you need to have VBA code that can list files in a folder. Â Here is a simple code for you,…
How to Add Outlook Reference in Excel VBA? To automate Outlook based tasks from Excel you need to add Outlook Object Library (Microsoft Outlook XX.X Object Library) in Excel References. You can follow below steps…
VBA Code to Browse a Folder Quite often a VBA developer requires code to browse a folder. This is mainly for saving the output file or reading the input file(s). Below is the VBA code…
Working with huge data is always exciting and challenging. From 2007 version onward, Excel is supporting more than a million rows in each worksheet. One of the common problems with huge data is “Duplicates” and the bigger problem is to identify and remove these duplicates. In this article, we will be sharing 4 ways to delete duplicate records from your data.
VBA to Read Excel Data Using Connection String Sometimes as a programmer you need to read heavy (more then 5 MB) Excel files. There are two ways you can read data from Excel files: Open…
Time & Motion Tracker is an MS Excel based tool which helps you to track Start and End time of any type of transaction or activity. The tool is developed using VBA coding which helps you to protect manual manipulation in the data by the user. It is also easy to use, just click on Start (shortcut: Ctrl+Shift+A) or Stop (Ctrl+Shft+S) buttons to record the time stamp.