I have some code I’ve used to change the cell fill color when a cell is clicked, if the same cell is clicked again the cell fill color is is then reset back to no fill color.
If Not Intersect(Target, Range("B2:H2")) Is Nothing Then
If Target.Interior.ColorIndex = 8 Then
Target.Interior.ColorIndex = 0
Else
Target.Interior.ColorIndex = 8
End If
End If
I would like to modify this code in two ways if it is possible. The first thing I want to do is to click a cell in a range, say any cell in B2 – H2 to change the color but if another cell in the range is clicked I would like it to automatically remove and reset the previously colored cell back to no fill color.
Also, and I may be asking a lot, is there any way to set up code in a range as described above but to limit the number of cells that can be colored at the same time, say a maximum of three cells in a range of say B2 – H2 that can be colored at the same time?
Thanks if anyone can advise.
If Not Intersect(Target, Range("B2:H2")) Is Nothing Then
If Target.Interior.ColorIndex = 8 Then
Target.Interior.ColorIndex = 0
Else
Target.Interior.ColorIndex = 8
End If
End If
I would like to modify this code in two ways if it is possible. The first thing I want to do is to click a cell in a range, say any cell in B2 – H2 to change the color but if another cell in the range is clicked I would like it to automatically remove and reset the previously colored cell back to no fill color.
Also, and I may be asking a lot, is there any way to set up code in a range as described above but to limit the number of cells that can be colored at the same time, say a maximum of three cells in a range of say B2 – H2 that can be colored at the same time?
Thanks if anyone can advise.