I am trying to create a button that upon one click, will check a specific cell in 10 sheets of a workbook, and recolour the tabs depending on a cell value.
For example,
- If cell E15 > 18, then the tab colour should turn green.
- If cell E15 < 18, then the tab colour should turn red.
All 10 tabs should be evaluated and recoloured upon a single button click.
So far my macro looks like this, giving just three sheets for an example. It's very crude but I am very new to VBA (1 day).
My main issue is that it works for the first tab, but then opens the second tab and says "Object Required"
Sub Update_Tab_Colour_One_Click()
Sheets(4).Activate
If Cells(13, 11).Value > 18 Then
With ActiveWorkbook.ActiveSheet.Tab
.Color = vbGreen
End With
Else
With ActiveWorbook.ActiveSheet.Tab
.Color = vbRed
End With
End If
Sheets(5).Activate
If Cells(13, 11).Value > 18 Then
With ActiveWorkbook.ActiveSheet.Tab
.Color = vbGreen
End With
Else
With ActiveWorbook.ActiveSheet.Tab
.Color = vbRed
End With
End If
Sheets(6).Activate
If Cells(13, 11).Value > 18 Then
With ActiveWorkbook.ActiveSheet.Tab
.Color = vbGreen
End With
Else
With ActiveWorbook.ActiveSheet.Tab
.Color = vbRed
End With
End If
End Sub