VBA to group rows that are between blank cells

brianallen0

New Member
Joined
Jul 21, 2015
Messages
11
Hi,

Ive search and tried to modify several variations of vba code I was able to find on the internet but cant seem to get the macro to work the way I want it. I basically have several rows with data and beneath is a subtotal line in a different column. I basically just need the code to read column D and group every row that is between these blank rows. All help is greatly appreciated example below.

Thanks!

Before
Blank
Numbers
Numbers
Numbers
Numbers
Blank

<tbody>
</tbody>

After
Blank
Group
Blank

<tbody>
</tbody>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
Code:
Sub GroupRows()
   Dim Rng As Range
   For Each Rng In Range("D2", Range("D" & Rows.count).End(xlUp)).SpecialCells(xlConstants).Areas
      Rng.EntireRow.Group
   Next Rng
End Sub
 
Upvote 0
How about
Code:
Sub GroupRows()
   Dim Rng As Range
   For Each Rng In Range("D2", Range("D" & Rows.count).End(xlUp)).SpecialCells(xlConstants).Areas
      Rng.EntireRow.Group
   Next Rng
End Sub

Wow that code is way less complex then I thought I needed, it worked perfectly thank you!!!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
Hi question maybe this code isn't working for me cause it's a string (letters) instead of numbers. but i need to group blanks together too same thing as the image above. I am trying to see if Row B has values. If there is no values in the data then group those.
Row A: B
1abc
0
0
1abc
1abc
1abc
 
Upvote 0
Hi & welcome to MrExcel.

You are trying to group blank rows, whereas the OP was trying to group rows with values.
Rather than posting to a 6 year old, you would be better off starting a thread of your own.
 
Upvote 0

Forum statistics

Threads
1,221,544
Messages
6,160,438
Members
451,646
Latest member
mmix803

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