I have attempted various iterations of the below and some have worked first time around, then not after, some not at all.
In short cell b2 on all sheets can be one of 6 text entries, (complete, in progress, scrapped, future works, parked, held) to show the currwnt state of that specific piece of work. To further help at a glance I want to update tab colours based on b1 as well.i.e if in progress B2 goes green, so does that tab.
Current code:
Private Sub tabcolour_Change(ByVal Target As Range)
Select Case Range("$b$2").Value
Case "In progress"
.Color = 43
Case "Held"
.Color = 6
Case "Scrapped"
.Color = 3
Case "Parked"
.Color = 28
Case "Complete"
.Color = 55
Case "Future Works"
.Color = 53
Case Else
.ColorIndex = xlColorIndexNone
End Select
End With
End Sub
I updated it slightly as still not working. The article I used below.
Excel VBA: automatically adjust tab colour
It won't be seen as a macro whilst I have "ByVal Target As Range" between () on the first line. But if I remove it it doesn't work.
It did work correctly once but then didn't change the colour of the cell after and threw up an error (this was a couple of hours ago now, so can't remember the message sorry).
It is probably something very basic, but alas so is my knowledge.
Could someone point me in the right direction please?.
**************EDIT/UPDATE**********************
Current code courtesy of Darren:
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("B1"), Target) Is Nothing Then
With ActiveSheet.Tab
Select Case Target
Case "In Progress"
.Color = RGB(153, 204, 0)
Case "Held"
.Color = RGB(255, 255, 0)
Case "Parked"
.Color = RGB(0, 255, 255)
Case "Complete"
.Color = RGB(128, 0, 128)
Case "Future works"
.Color = RGB(153, 0, 167)
Case "scrapped"
.Color = RGB(194, 24, 7)
Case Else
.ColorIndex = xlColorIndexNone
End Select
End With
End If
End Sub
The tab colours do change, but not for "In Progress", "Future works", or "scrapped", the rest work fine?. I have changed the RGB values incase it is those colours, but it's still the same?. No colour values make these change, and the text going into the box is right as I have now added this as a data validation too (using a list on another tab). I complete the drop down now, and for 3 of the 6 it works fine???.