Is reverse Conditional Formatting possible?

Scancon

New Member
Joined
Jan 19, 2003
Messages
12
Hi, I want to mark a cell (e.g. A1) with a '1' if B1 is red and '0' if B1 has no color. Is this possible?
(I have a large sheet, with rows in different colors, and I need to sort the rows by color).
TIA! /Hans
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
It is possible to do this using VBA. Perhaps you can be more specific about which cells you want to change based on which other cell's colours.
 
Upvote 0
Sure!

I have the sheet where the rows are either red or not-colored.
I insert a new column as column A.
If cell B1 is red, I want to set the value of cell A1 to 1.
If cell B1 is not red, I want to set the value of cell A1 to 0.
Etc. through all the rows in the sheet.
(I have corrected a mistake in my original posting, sorry!).
/Hans.
 
Upvote 0
This should do what you want (and it will insert a column for you as well so you don’t have to do this yourself)

Code:
Sub SortColours()
Dim limit As Long
Dim c As Long
Columns(1).Insert shift:=xlToLeft
limit = Cells(Rows.Count, 2).End(xlUp).Row
For c = 1 To limit
    If Cells(c, 2).Interior.ColorIndex = 3 Then
        Cells(c, 1) = 1
        Else: Cells(c, 1) = 0
    End If
Next c
End Sub
 
Upvote 0
Hi Lewiy,

Thanks a lot - it works like a charm!

I just had a small problem, re. the setting of the variable 'limit'. If you pass a blank cell, the counting seems to stop, like when du do an 'end-down' to reach the end of data in a column. This was solved - and once again thank you for your kind assistance!

/Hans
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,668
Members
448,977
Latest member
moonlight6

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