VBA to format multiple columns and rows with shared attributes into single row with subtotals

Gimics

Board Regular
Joined
Jan 29, 2014
Messages
164
Office Version
  1. 365
Platform
  1. Windows
Hello,

I would like to run a VBA routine that takes a data table with unique records and creates a single list with multiple subtotals rows (and excel groupings, if possible), based on the commonalities. I bet this already exists out there somewhere, but I couldn't figure out a good search term to find a useful post. Can anyone help me out?

Example current data:
JoeSteveCanadaFood
JoeSteveCanadaBeverage
JoeSteveUSAFood
JoeSteveUSABeverage
JoeRenaeCanadaFood
JoeRenaeCanadaBeverage
JoeRenaeUSAFood
JoeRenaeUSABeverage
JoeKyleUSAFood
JoeKyleUSABeverage

<tbody>
</tbody>

Example format after macro (ignore third column; just a comment column for this post):

CanadaFoodUnique
CanadaBeverageUnique
USAFoodUnique
USABeverageUnique
SteveFoodSubtotal for Steve
SteveBeverageSubtotal for Steve
CanadaFoodUnique
CanadaBeverageUnique
USAFoodUnique
USABeverageUnique
RenaeFoodSubtotal for Renae
RenaeBeverageSubtotal for Renae
USAFoodUnique
USABeverageUnique
KyleFoodSubtotal for Kyle
KyleBeverageSubtotal for Kyle
JoeFoodSubtotal for Joe (includes all levels under Joe)
JoeBeverageSubtotal for Joe (includes all levels under Joe)

<tbody>
</tbody>

This is an incredibly simplified version of what I'm working with. Not all people would have food/beverage; not all people would have all regions; and there are many more columns and rows than this, but they all drill up from right to left. I thought of having the macro use all unique values through all levels (so copy and paste Food and Beverage for everyone, and USA and Canada for everyone), and then run a macro to remove all blank rows (based on lookup formulas I am using after the report formatted). That's an option, if it's easier to built the chart that way.

I just need this to build out the row descriptions; I will have lookup formulas for pulling the data from my table based on rebuilt label column.

Thoughts? I just can't wrap my mind around looping through unique records and positioning the subtotals appropriately.

Thanks in advance
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Bump; any takers? Or anyone heard of something similar and can refer me to a search term/other posting?
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,698
Members
449,117
Latest member
Aaagu

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