One colour per row only

Tigerexcel

Active Member
Joined
Mar 6, 2020
Messages
493
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a list with 3 columns, each row is allowed one cell to have a background fill eg yellow. Is there a way to change the particular coloured cell in a row to another column and then have the original cell revert to standard fill background. In this particular exercise I need to ensure that no row has more than one background coloured cell.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,
Can you show with some sample data?
I'm thinking you need VBA to accomplish this.
Perhaps tag you post if still possible.
 
Upvote 0
Hi G.

Model AModel BModel C
Jane669656
Ken756365
Fred638452
Mary815493

Cells which have background coloured red cells are 66, 63, 52, 54. I need to be able to change a row eg Jane to say Model B so that it has a red background fill but the 66 becomes a cell with a normal background. No person (row) can have more than one background coloured cells at any one time.
 
Upvote 0
I came up with this if you don't mind using a column to set the highlight selection.
It's possible with VBA to simply click on the cell to colour it and remove background from the others. I'm sure the active and fine coders here can provide it.
Book1
ABCDE
1Model AModel BModel CHighlight
2Jane669656a
3Ken756365b
4Fred638452c
5Mary815493a
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B2:D5Expression=MATCH($E2;RIGHT($B$1:$D$1;1))=COLUMN()-1textNO
 
Last edited:
Upvote 0
You could put this in the sheet's code module.
Double clicking a cell in columns B:D will change its fill to red. Only one of those cells will be red. (Double clicking on a red cell will make it white)

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    With Target
        If 2 <= .Column And .Column <= 4 Then
            Cancel = (.Interior.Color = vbRed)
            .EntireRow.Range("B1:D1").Interior.ColorIndex = xlNone
            If Not Cancel Then .Interior.Color = vbRed
            Cancel = True
        End If
    End With
End Sub
 
Last edited:
Upvote 0
You could put this in the sheet's code module.
Double clicking a cell in columns B:D will change its fill to red. Only one of those cells will be red. (Double clicking on a red cell will make it white)

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    With Target
        If 2 <= .Column And .Column <= 4 Then
            Cancel = (.Interior.Color = vbRed)
            .EntireRow.Range("B1:D1").Interior.ColorIndex = xlNone
            If Not Cancel Then .Interior.Color = vbRed
            Cancel = True
        End If
    End With
End Sub
Hi Mike,

I have tried this but when I double-click, it just launches edit mode.
 
Upvote 0
Did you put it in the sheet's code module or a normal code module?
I tried it in both and couldn't get it to work. I opened a new workbook with some new data and it works fine.
Just one other question, will this work in a Pivot table? Once you double-click PTs open another worksheet with the underlying data.
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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