Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - Click on cell changes/cycles through colors

Status
Not open for further replies.

skipjakk

Technical User
Feb 25, 2002
18
US
I'm trying to create a section in a spreadsheet that will allow a user to click on a cell and change its color. I could probably code something, but wondering if there's toolbox control I could use that would work better? Or is coding the best route, as I would have to read the cell color for decisioning later on?
 
Record a macro of yourself changing cell colors. You can customize the code to suit your needs, and place the code in the Worksheet_BeforeDoubleClick event.

I was able to come up with this pretty quickly by doing just that. It will toggle any cell on Sheet1 between bright green and no fill on a double-click.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Select Case Target.Interior.ColorIndex
        Case xlNone
            With Target.Interior
                .ColorIndex = 4
                .Pattern = xlSolid
            End With
        Case Else
            Target.Interior.ColorIndex = xlNone
    End Select
End Sub

If you get stuck with any specific code, please repost with your code.

Hope this helps,
Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top