Create a Pivot Table for each column in a datasheet

Mr_Ragweed

Board Regular
Joined
Dec 10, 2012
Messages
74
Hello, I'm new to loops. I need to write a macro that creates a PT for each column in a datasheet. The number of columns and rows is variable. The PT is simple it will only use Column A and then 1 other column at a time. I would show you my code but i'm having trouble with where to even start. I'm struggling with the Ranges (assuming dynamic ranges?) as much as I am writing a loop. Possible declarations are as follows:

' DCol stands for DataColumn
Dim DCol as Column
Dim WSD as Worksheets("name")
Dim FinalRow as Long
Dim FinalCol as Long
Dim PT as PivotTable
Dim ("A") as Range
Dim ? as Range

FinalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp)
FinalCol = WSD.Cells(1, Application.Columns.Count).End(xlToLeft).Column

So from here i have to type in english what i want:
For each DCol & "A", create a PT.

I can handle the location and formatting of the tables (or i've at least convinced myself that I can).

When we solve this I will probably be back with Userform questions as i want to make a userform that lets the user control the groupings of each resultant PT. If it helps the data sheet is actually from a much larger PT. If its easier to extract what i need from there, i'm all ears. Users will never see anything but the tables i'm trying to create.

Thanks in advance, Mr_Ragweed.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
So the DCol thing doesn't work - big surprise as i knew i was reaching. I'm think that maybe an easier way to do this would be to create a PT using columns A and B, then delete column B -shifting everything left, then create another PT using Columns A and the 'new' column B, etc, etc until there is nothing in Column B.
I think i can write the "create a PT from Columns A and B" and the delete the column part. It's the looping through to the end part that makes me nervous.
 
Upvote 0
WOW! Nevermind. Sometimes you cant see the forest for the trees. The "Show Report Filter Pages" option does the trick exactly the way i needed it. I knew my question couldn't be unique. Sorry for wasting the time of anyone who read this.
(By the way, i was oh so close to solving this on my own. The solution i posed in my second post was definitely on the right track.)
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,128
Members
452,381
Latest member
Nova88

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