Change worksheet tab color if sheet is NOT empty

Ruckus

New Member
Joined
Jun 7, 2011
Messages
15
I have a workbook with an 'Additional Info' sheet at the end of the book.

My problem is that info is only entered on to this sheet about 5% of the time and I end up missing it because it's not common.

I've searched these forums, googled and attempted to modify code for hours now without success.

What would the VBA code be to change the color of the tab if anything is entered into any cell of that sheet
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this: right click the sheet tab, select View Code and paste in

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If WorksheetFunction.CountA(Me.Cells) <> 0 Then Me.Tab.Color = RGB(255, 0, 0)
End Sub
 
Upvote 0
That works :)

Though if they enter a value and then remove it, it remains colored. Is there a way of changing it back to 'no color' if they enter something then change their mind and delete?
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Cells.Find("*") Is Nothing Then
        ActiveSheet.Tab.ColorIndex = xlNone
    Else
        ActiveSheet.Tab.ColorIndex = 3
    End If
End Sub
 
Upvote 0
Maybe this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Tab.Color = xlnone
If WorksheetFunction.CountA(Me.Cells) <> 0 Then Me.Tab.Color = RGB(255, 0, 0)
End Sub
 
Upvote 0
For some reason when I tried AlphaFrog's code it would color other tabs if I clicked them before clicking somewhere else in the 'Additional Info' tab.

Strange!


VoG: That works! Thank you once again.
 
Upvote 0
Oops! If I share the workbook, the code no longer works and I receive an error message if I attempt to enter anything in that sheet.

"Run-Time Error '1004':

application-defined or object-defined error"


From Microsoft: 'This issue may occur if one or more of the cells in an array (range of cells) contain a character string that is set to contain more than 911 characters.'

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Me.Tab.Color = xlNone
If WorksheetFunction.CountA(Me.Cells) <> 0 Then Me.Tab.Color = RGB(255, 0, 0)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

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