changing cell color with double click

vworm1097

New Member
Joined
Mar 1, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am absolutely new at this and can't seem to find what I need, any help would be greatly appreciated...

I have a survey type form with several questions in column A and a range of ratings (1-5) in cells B-F. I want the end user to choose one of the ratings based on the question and when they click on a cell (B-F), I want the cell to change colors (both the cell fill and font) so that it stands out and then when the cell is clicked on again, say they change their mind or wanted to give it a different rating, the cell returns to the original color (both the cell fill and font). So far what I have found will do this when the cell is clicked on but when it is clicked on again it looses the original cell color. Even when the cell is no fill (white) with grey font as the original colors, when the cell is clicked on and then clicked on again it does not keep the original colors and it is obvious that the end used clicked on a cell then changed their mind and clicked on a different cell.

I think this would be pretty basic stuff but I am at a loss.
Thank you.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Put the following code in the code window of the sheet where you have the 'form'. You'll need to change the colors/fonts to suit. The code assumes that the original cell fill color is vbWhite.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, cancel As Boolean)
    If Not Intersect(Range("B:F"), Target) Is Nothing Then
        With ActiveCell
            If ActiveCell.Interior.Color = vbWhite Then
                .Interior.Color = vbBlue
                .Font.Color = vbWhite
                .Font.Bold = True
            Else
                .Interior.Color = vbWhite
                .Font.ThemeColor = xlThemeColorDark1
                .Font.TintAndShade = -0.4
                .Font.Bold = False
            End If
        End With
        cancel = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,808
Messages
6,181,072
Members
453,020
Latest member
mattg2448

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top