Insert row and fill with grey between groups

abenitez77

Board Regular
Joined
Dec 30, 2004
Messages
149
I have a button that when clicked, it starts formatting an excel file which I select. I have data in columns A thru L. The rows will vary for each file I get, which I get biweekly. In row A, I have a column called colors and the cell contains a string with the name of a color (ie see below). I want to insert a row between each color that changes and fill the cells with grey in columns B thru H. How can I do this?
Red
Red
Red
Green
Green
Green
Blue
Orange
Orange
Yellow
White
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
VBA Code:
     r = Range("a" & Rows.Count).End(xlUp).Row                  'number last row
     For i = r - 1 To 1 Step -1                                 'loop backwards
          'Debug.Print Cells(i, 1).Value & "    " & Cells(i + 1, 1).Value
          If Cells(i, 1).Value <> Cells(i + 1, 1).Value And WorksheetFunction.CountA(Cells(i, 1).Resize(2)) = 2 Then     '2 successive cells, non is empty and have different value
               Rows(i + 1).Insert                               'insert row inbetween
               Cells(i + 1, 2).Resize(, 7).Interior.Color = RGB(200, 200, 200)     'fill with grey cemms
          End If
     Next
 
Upvote 0
Solution

Forum statistics

Threads
1,215,606
Messages
6,125,814
Members
449,262
Latest member
hideto94

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