one4youman
New Member
- Joined
- Oct 5, 2018
- Messages
- 13
Below is a piece of code from another thread where double clicking on a cell changes the cell to red. If you double click on the cell again it changes back to its original color format.
I am looking to see if there is a way to add additional colors to the choices. For Example, the first double click produces Green, second Red, third yellow, fourth gold, fifth white, and lastly the sixth would change it back to its original color.
I am looking to see if there is a way to add additional colors to the choices. For Example, the first double click produces Green, second Red, third yellow, fourth gold, fifth white, and lastly the sixth would change it back to its original color.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, Cancel As Boolean)
'https://www.mrexcel.com/forum/excel-questions/634133-double-click-change-cell-colour.html
Static Fst As Boolean
Static rng As Range
Static ray
Dim c As Long
Dim Dn As Range
Dim Rw As Long
If Fst = False Then
Set rng = ActiveSheet.UsedRange
ReDim ray(1 To rng.Count, 1 To 2)
For Each Dn In rng
c = c + 1
ray(c, 1) = Dn.Address: ray(c, 2) = Dn.Interior.ColorIndex
Next Dn
Fst = True
End If
For Rw = 1 To UBound(ray)
If ray(Rw, 1) = target.Address Then
target.Interior.ColorIndex = IIf(target.Interior.ColorIndex = 3, ray(Rw, 2), 3)
End If
Next Rw
End Sub
Last edited: