I would like to change the colour of a cell by single-clicking on it, the colour to be determined by the column that the cell is in.
In other words, when single-clicked, any cell in column 2 would turn green, a cell in column 3 would turn orange and a cell in column 4 would turn red. Right-click on any cell would remove any colour.
The code I have found is:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Select Case Target.Interior.ColorIndex
Case xlNone, 4: Target.Interior.ColorIndex = 3
Case Else: Target.Interior.ColorIndex = 4
End Select
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Interior.ColorIndex = xlNone
End Sub
However, this code requires a double-click, not a single-click, repeated double-clicks change the colour and the colour does not depend on the column that the cell is in.
I would be very grateful if someone who knows how to code in vba could modify the above code to do what I need, as set out above.
Thank you very much in anticipation.
useful :confused: