Highlight rows in 3 different color groups

spectraflame

Well-known Member
Joined
Dec 18, 2002
Messages
830
Office Version
  1. 365
Platform
  1. Windows
I have been asked to take a list of data, which changes each time it is imported into Excel, and divide the sheet into 3 groups by color using a macro. The sheet contains meter information and the color coding denotes which year each should be tested in. I realize that since the list of meters is going to change, there may not be an equal number of meters in each highlighted group but that is OK.

My guess is that I would need to determine the number of used rows (column C is the first column in the sheet that contains data in ever row) and divide by 3. The rest would then have to be pasted to a Select statement so the macro could highlight them. Then with desire rows selected, choose a highlight color. Typing it out makes it sound easy but I have no idea is something like this is even possible.

My other thought was to number each row by 3's. I could then just sort the list to determine the desired test year.

If it matters, the sheet in question has less than 400 rows.

If you have a better idea, I am open to anything.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
so you just want to divide the data into three sections? There is no criteria other than that?
 
Upvote 0
That is correct. The only requirement is that management wants a single report to print with the data broken down by the 3 colored sections.

Am I making this more complicated than it needs to be?
 
Upvote 0
try this

Code:
Sub MeterChecks()
Dim LR As Long, MCC As Long, MCC2 As Long, MCC3 As Long
LR = ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
MCC = LR / 3
MCC2 = MCC + 1
MCC3 = MCC2 + 1 + MCC
Rows("1:" & MCC).Font.ColorIndex = 12
Rows(MCC2 & ":" & MCC3).Font.ColorIndex = 25
Rows(MCC3 & ":" & LR).Font.ColorIndex = 30
End Sub
 
Upvote 0
That is great!

If I needed to cut that into smaller sections, would I use this approach?

Sub ResidentialMeterChecks()
Dim LR As Long, MCC As Long, MCC2 As Long, MCC3 As Long, MCC4 As Long, MCC5 As Long
Sheets("RESIDENTIAL").Select
LR = ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
MCC = LR / 5
MCC2 = MCC + 1
MCC3 = MCC2 + 1 + MCC
MCC4 = MCC3 + 1 + MCC2
MCC5 = MCC4 + 1 + MCC
Rows("2:" & MCC).Interior.ColorIndex = 35
Rows(MCC2 & ":" & MCC3).Interior.ColorIndex = 34
Rows(MCC3 & ":" & MCC4).Interior.ColorIndex = 36
Rows(MCC4 & ":" & MCC5).Interior.ColorIndex = 37
Rows(MCC5 & ":" & LR).Interior.ColorIndex = 39
Sheets("INSTRUCTIONS").Select
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,453
Members
452,915
Latest member
hannnahheileen

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