Group cells without the totals (conditional grouping)

Migaspt

New Member
Joined
Mar 12, 2014
Messages
22
Hello!

I'm trying to write the code to run a macro on VB to group rows until the totals.


Example:

TITLE 1TITLE 2TITLE 3TITLE 4%
XX1X1198
XX2X2187
XX3X3120
XX1X1210
XX3X32
X TOTAL53.75
YY1Y1168
YY1Y1298
YY2Y2114
Y TOTAL58.44
Grand Total56.35

<tbody>
</tbody>

What I need is to group the Xs and Ys until the totals. The code should stop the groupings when there is the "Grand Total" in column A.
-Some groups can have only one cell to group.
-Grouping should start at the 14th row

(Another way to write it could be to group until the blank cells in column B?)


Can you help me with this?

Thank you very much in advance!:)
 
when you look in excel help group and ungroup refer to pivot table items

I cannot see how grouping a few cells together is a benefit - somebody else please step in to help.

In the mean time forget your actual data, makeup a pretend table of data, tell us how you want to analyse it and provide a desired finished table, so we can see what you want in a very simple way.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I need to group rows to this file.

What I asked was if I can use code to run a macro that automaticly groups the rows I need grouped.

How can I upload the table here?

Is this code possible?


So far I got this through the Macro Recorder:
Code:
Sub groups()
'
' groups Macro
'
 
'
    Sheets("Sheet 1").Activate
    Range("J14").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Rows.Group
    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Rows.Group

Can I add to this code the conditions that I need?
 
Upvote 0
make a little spreadsheet with raw data and analysed data, select all the cells, copy, go to forum, reply, paste, reply
 
Upvote 0
What I need is this:

ABCDEFgroups
1TITLE 1TITLE 2TITLE 3TITLE 4%
2XX1X1198O
3XX2X2187O
4XX3X3120O
5XX1X1210O
6XX3X32O
7X TOTAL53.75
8YY1Y1168O
9YY1Y1298O
10YY2Y2114O
11Y TOTAL58.44
12Grand Total56.35

<tbody>
</tbody>

<tbody>
</tbody>

<tbody>
</tbody>

O = row to be grouped

Can I use a vb code to group these rows?

PS- Thank you very much for your patience oldbrewer :biggrin:
 
Last edited:
Upvote 0
I want to group the Xs and Ys on different groups.

The groups don't have a particular size, it depends on the data.

The code should stop to group rows when it is written "Grand Total" in column A.
 
Upvote 0
By recording a macro doing what I need I got this code:Code:

Code:
Sub groups()
'
'groups Macro

'
 '
    Sheets("Sheet 1").Activate
    Range("J14").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Rows.Group    Selection.End(xlDown).Select
    Selection.End(xlDown).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Rows.Group

I used the Ctrl+Shift+Down to only select the rows with data to group.

Is it understandable now? I'm not sure how to say it differently :confused:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,546
Members
449,169
Latest member
mm424

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