Macro to look for common value in Column A, and highlight those rows particular color

bjcf33183

New Member
Joined
Dec 11, 2017
Messages
8
Hi all,
I'm trying to figure out how to create a macro which would look for a specified value in Column A, and highlight subsequent columns for that value in a particular color. Then, if it finds a different value in Column A, it would highlight those rows a different color, and so on.
Here's an example of what I'm referring to:

So there's just 2 columns. Column A has a numeric value, Column B has a name. So what I'm looking to do is highlight all of the four rows in which Column A = 1 a random color. Then, it would highlight the next two rows (in which Column A = 2) a different color. Then, finally, it would highlight the last five rows (Column A = 3) another color.
Column A Column B
1 Joe
1 Bob
1 Mary
1 Tom
2 Mike
2 Suzy
3 Lauren
3 Brian
3 Bill
3 Mary
3 Steve

Any help would be appreciated - thanks! :confused:
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Do you know in advance what the numbers are going to be? Or are you saying:


  • Use one color starting in row 1 until the number in column A changes
  • Use another color starting in that row until the number in column A changes again
  • Use another color starting in that row until the number in column A changes again


Do you know in advance how many different numbers there will be?

Do you have to use a different color for each new number, or can you alternate back and forth between two colors?

This can be done with conditional formatting but you need a different rule for each color. It could also be done with VBA.

I just want to make sure it's clear what the logic is for the numbers. You started out by saying " a specified value in Column A" but you never specified a value for column A. It looks like whatever the value is in the first row is the one you want to make the first color.
 
Last edited:
Upvote 0
Do you know in advance what the numbers are going to be?

No - this would be variable

Do you know in advance how many different numbers there will be?


Nope - this is also variable.

Do you have to use a different color for each new number, or can you alternate back and forth between two colors

Alternating back and forth between 2 colors would work as well.

Thanks!
 
Upvote 0
Assuming your data start in row, select A1 to the last row, in conditional formatting use this formula
=MOD(SUM(--(FREQUENCY($A$1:$A1,$A$1:$A1)>0)),2)<>0
select a format
Then create another rule with
=MOD(SUM(--(FREQUENCY($A$1:$A1,$A$1:$A1)>0)),2)=0
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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