Color Banding a range

RLJ

Active Member
Joined
Mar 15, 2011
Messages
417
Office Version
  1. 365
Platform
  1. Windows
I need code to put a color band on a range of rows. In Column B I have numbers and each new number, I need a color band on the row. However sometimes the numbers repeat and need the range of rows color banded. For the Eample below, Rows 16:17 & 19 & 21:22, etc color banded

Ins Exp - 2012-02


<TABLE style="BACKGROUND-COLOR: #ffffff; PADDING-LEFT: 2pt; PADDING-RIGHT: 2pt; FONT-FAMILY: Arial,Arial; FONT-SIZE: 10pt" border=1 cellSpacing=0 cellPadding=0><COLGROUP><COL style="WIDTH: 30px; FONT-WEIGHT: bold"><COL style="WIDTH: 70px"></COLGROUP><TBODY><TR style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt; FONT-WEIGHT: bold"><TD> </TD><TD>B</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">15</TD><TD style="TEXT-ALIGN: center">28000110</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">16</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #c0c0c0">33000058</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">17</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #c0c0c0">33000058</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">18</TD><TD style="TEXT-ALIGN: center">33000061</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">19</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #c0c0c0">40000032</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">20</TD><TD style="TEXT-ALIGN: center">49000003</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">21</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #c0c0c0">49000022</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">22</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #c0c0c0">49000022</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">23</TD><TD style="TEXT-ALIGN: center">49000023</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">24</TD><TD style="TEXT-ALIGN: center">49000023</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">25</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #c0c0c0">63000060</TD></TR><TR style="HEIGHT: 18px"><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #cacaca; FONT-SIZE: 8pt">26</TD><TD style="TEXT-ALIGN: center; BACKGROUND-COLOR: #c0c0c0">63000060</TD></TR></TBODY></TABLE>
Thanks for your help
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I need code to put a color band on a range of rows. In Column B I have numbers and each new number, I need a color band on the row. However sometimes the numbers repeat and need the range of rows color banded. For the Eample below, Rows 16:17 & 19 & 21:22, etc color banded

Ins Exp - 2012-02


<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 10pt; FONT-FAMILY: Arial,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 70px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD></TD><TD>B</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">15</TD><TD style="TEXT-ALIGN: center">28000110</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">16</TD><TD style="BACKGROUND-COLOR: #c0c0c0; TEXT-ALIGN: center">33000058</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">17</TD><TD style="BACKGROUND-COLOR: #c0c0c0; TEXT-ALIGN: center">33000058</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">18</TD><TD style="TEXT-ALIGN: center">33000061</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">19</TD><TD style="BACKGROUND-COLOR: #c0c0c0; TEXT-ALIGN: center">40000032</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">20</TD><TD style="TEXT-ALIGN: center">49000003</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">21</TD><TD style="BACKGROUND-COLOR: #c0c0c0; TEXT-ALIGN: center">49000022</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">22</TD><TD style="BACKGROUND-COLOR: #c0c0c0; TEXT-ALIGN: center">49000022</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">23</TD><TD style="TEXT-ALIGN: center">49000023</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">24</TD><TD style="TEXT-ALIGN: center">49000023</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">25</TD><TD style="BACKGROUND-COLOR: #c0c0c0; TEXT-ALIGN: center">63000060</TD></TR><TR style="HEIGHT: 18px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">26</TD><TD style="BACKGROUND-COLOR: #c0c0c0; TEXT-ALIGN: center">63000060</TD></TR></TBODY></TABLE>
Thanks for your help
This can be done using conditional formatting or do you want a VBA solution?
 
Upvote 0
Conditional Formatting witll be great.
 
Upvote 0
Conditional Formatting witll be great.
Try this...

Book1
B
1528000110
1633000058
1733000058
1833000061
1940000032
2049000003
2149000022
2249000022
2349000023
2449000023
2563000060
2663000060
Sheet1

There must be a cell above the first cell to be formatted and this cell must not contain the same entry as the first cell in the range to be formatted.

Select the entire range to be formatted B15:B26.
Conditional Formatting
Use the "formula option"
Use this formula:

=MOD(SUMPRODUCT(--(B$14:B14<>B$15:B15)),2)=0

Set the desired fil color
OK out

This will slow things down if you need to format 1000's of rows of data.
 
Upvote 0
Try this...

Sheet1

B
1528000110
1633000058
1733000058
1833000061
1940000032
2049000003
2149000022
2249000022
2349000023
2449000023
2563000060
2663000060

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:72px;"></colgroup><tbody>
</tbody>



There must be a cell above the first cell to be formatted and this cell must not contain the same entry as the first cell in the range to be formatted.

Select the entire range to be formatted B15:B26.
Conditional Formatting
Use the "formula option"
Use this formula:

=MOD(SUMPRODUCT(--(B$14:B14<>B$15:B15)),2)=0

Set the desired fil color
OK out

This will slow things down if you need to format 1000's of rows of data.

Hi Biff,
I can get this to work perfectlly in a single range B15:B26 but how do I get it to work for say A15:F26?
Thanks and Merry Christmas
 
Upvote 0
Try this

select your data that is range A15:f26

then go to conditional formatting using formula and type the formulla

=COUNTIF($B$14:$B$26,$B2)>1

Selet which ever color you like.

Thanks
 
Upvote 0
Try this

select your data that is range A15:f26

then go to conditional formatting using formula and type the formulla

=COUNTIF($B$14:$B$26,$B2)>1

Selet which ever color you like.

Thanks

With the below i get no fill

=COUNTIF($B$14:$B$26,$B2)>1

and with the below I get fill but not working correctly

=COUNTIF($B$14:$B$26,$B14)>1

Thanks
 
Upvote 0
thanks for pointing the mistake. . . do u want to highlight duplicates in A15:F26 ?? each column at a time?? please explain a bit more
 
Upvote 0

Forum statistics

Threads
1,215,334
Messages
6,124,319
Members
449,154
Latest member
pollardxlsm

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