This has been an extremely frustrating issue. In the attached workbook, I am looking for particular cells to either be coloured upon being clicked or un-coloured upon a second click.
The code provided seemingly does nothing, even after Saving, Closing, then reopening the file. These are the versions tried, and before anyone asks, all lines were commented out before trying the newest version.
The ultimate aim is to allow the User to select the preferred months of the year for his/her area for each of the sectors in Range A4 to A9 as the criteria.Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim ws As Worksheet Dim targetCell As Range Set ws = ThisWorkbook.Sheets("Sheet1") If Not Intersect(Target, ws.Range("B4:N4")) Is Nothing Then Set targetCell = Target If targetCell.Interior.Color = ws.Range("B4").Interior.Color Then targetCell.Interior.Color = xlNone Else targetCell.Interior.Color = ws.Range("B4").Interior.Color End If End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim targetCell As Range Dim orangeColor As Long Dim ws As Worksheet Set ws = ThisWorkbook.Sheets("Sheet1") orangeColor = RGB(255, 165, 0) ' Explicit orange color If Not Intersect(Target, ws.Range("B4:N4")) Is Nothing Then Set targetCell = Target If targetCell.Interior.Color = orangeColor Then targetCell.Interior.Color = xlNone Else targetCell.Interior.Color = orangeColor End If End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim targetCell As Range Dim orangeColor As Long Dim ws As Worksheet Dim targetRange As Range ' Explicitly declare Target Set ws = ThisWorkbook.Sheets("Sheet1") orangeColor = RGB(255, 165, 0) Set targetRange = Target ' Set targetRange If Not Intersect(targetRange, ws.Range("B4:N4")) Is Nothing Then Set targetCell = targetRange If targetCell.Interior.Color = orangeColor Then targetCell.Interior.Color = xlNone Else targetCell.Interior.Color = orangeColor End If End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) Call ToggleCellColor End Sub
Colours used with colour Index #
White, Background 1, 15% darker (16)
Orange (48)
Plum, Accent 5 (56)
Turquoise, Accent 4 Lighter 40% (10)
Red (3)
I've had that mmany swings and misses, I can't tell if i've been struck out or thrown out.




Reply With Quote