Testing a column in Excel to determine tab color

I have a column in Excel that contains either 1's or 0's, except for the top cell that contains the header.

If a 0 is within the column the tab becomes red. If there are no 0's the tab is green.

Thanks in advance for any help.
dgd1212Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZShaverCommented:
0
Patrick MatthewsCommented:
If the 0s and 1s are determined by formula, then put this in the worksheet's code module:

Private Sub Worksheet_Calculate()
    
    Dim rng As Range
    
    Set rng = Intersect(Me.Range("a:a"), Me.UsedRange) 'update as needed
    If Application.CountIf(rng, 0) > 0 Then
        Me.Tab.Color = vbRed
    Else
        Me.Tab.Color = vbGreen
    End If
    
End Sub

Open in new window


If you are actually entering the 0s and 1s:


Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim rng As Range
    
    Set rng = Intersect(Me.Range("a:a"), Me.UsedRange)
    If Application.CountIf(rng, 0) > 0 Then
        Me.Tab.Color = vbRed
    Else
        Me.Tab.Color = vbGreen
    End If
    
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NorieData ProcessorCommented:
You don't say which worksheet or column, but here's an example based on Column D in Sheet1
Dim ws As Worksheet
Dim cnt0 As Long

    Set ws = Worksheets("Sheet1")

    With ws
        cnt0 = Application.CountIf(.Range("D2:D" & .Range("D" & Rows.Count).End(xlUp).Row), 0)

        If cnt0 > 0 Then

            .Tab.ColorIndex = 3
        Else
            .Tab.ColorIndex = 4
        End If
    End With

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.