Change color on tab

KlausW

Active Member
Joined
Sep 9, 2020
Messages
378
Office Version
  1. 2016
Platform
  1. Windows
Hi I have a vague plan divided into months, I have tried with this VBA to get the color of the tab as the date you are in now to change the Danish name of the month is in cell E1, but it may not need to happen. The VBA code is in this production's directory, but it's not what's wrong, anyone can help?

VBA Code:
Private Sub Workbook_Open ()


Dim WS As Worksheet

Dim MountNu As String

MountNu = Range ("E1") & WorksheetFumktion.MountNow ()

For Each WS In ThisWorkbook.Worksheets

If WS.Name = MountNu Then

WS.Tab.ColorIndex = 4

Else

WS.Tab.ColorIndex = xlColorIndexNone

End If

Next


End Sub
All help will be appreciated

Regards Klaus W
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Are the tab names the full month name or are they three letter abbreviations?
 
Upvote 0
Ok, how about
VBA Code:
Private Sub Workbook_Open()


Dim WS As Worksheet

Dim MountNu As String

MountNu = MonthName(Month(Date))

For Each WS In ThisWorkbook.Worksheets

If WS.Name = MountNu Then

WS.Tab.ColorIndex = 4

Else

WS.Tab.ColorIndex = xlColorIndexNone

End If

Next


End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Private Sub Workbook_Open()


Dim WS As Worksheet

Dim MountNu As String

MountNu = MonthName(Month(Date))

For Each WS In ThisWorkbook.Worksheets

If WS.Name = MountNu Then

WS.Tab.ColorIndex = 4

Else

WS.Tab.ColorIndex = xlColorIndexNone

End If

Next


End Sub
And I put in this workbook ?
 
Upvote 0
That's right & it will run whenever you open the workbook.
 
Upvote 0
If you add the message box as shown
VBA Code:
MountNu = MonthName(Month(Date))
MsgBox MountNu
For Each WS In ThisWorkbook.Worksheets
what does it return?
 
Upvote 0
If you add the message box as shown
VBA Code:
MountNu = MonthName(Month(Date))
MsgBox MountNu
For Each WS In ThisWorkbook.Worksheets
what does it return?
It is returning the rigth month "May"
 
Upvote 0
But is it in Danish, assuming that's how the sheets are named?
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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