I am trying to create a sheet where our employees can click on a cell to highlight it notating they are working of the task, and then click it again when they are finished with it, and click it a 3rd time if they need to clear the highlight. So far I have come up with the below, which works except that I have to click another cell and come back to the same one again or it will try to edit the cell. I Just want 1 click color change, another click same cell color change 2, another click same cell color change 3. Is there any way to do this?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'If the target cell is clear
If Target.Interior.ColorIndex = xlNone Then
'Then change the background to the specified color
Target.Interior.ColorIndex = 6
'But if the target cell is already the specified color
ElseIf Target.Interior.ColorIndex = 6 Then
'Then change the background to the specified color
Target.Interior.ColorIndex = 3
'But if the target cell is already the specified color
ElseIf Target.Interior.ColorIndex = 3 Then
'Then clear the background color
Target.Interior.ColorIndex = xlNone
End If
End Sub
Double-click the cell, and then drag across the contents of the cell that you want to select. Click the cell, and then drag across the contents of the cell that you want to select in the formula bar.
In the Rule Description field, enter the formula: =OR(CELL(“col”)=COLUMN(),CELL(“row”)=ROW()) Click on the Format button and specify the formatting (the color in which you want the row/column highlighted). Click OK.
In the Properties window, (1) click on Alphabetic and (2) select ForeColor. After that, (3) click on the arrow to the right to display the color options, and (4) choose a color from the Palette (or System).
Add a BeforeDoubleClick event with this code in the same sheet:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Worksheet_SelectionChange Target
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With