Create Pivot Table Based on Dynamic Range

keen1598

New Member
Joined
Apr 2, 2013
Messages
16
So i have a worksheet with a small table on it using columns A:O. Using a starting point of cell B2 and then-- Cells.Find(What:="*", After:=[b2], SearchDirection:=xlPrevious).Select -- I am able to select the range in which I'd like to use for the pivot table. I've repeatedly tried to name this range by setting the currentregion.name to a string or a range, and every time i get an empty variable. Ive tried using activecell.currentregion to create a name using the Names.Add Name:= and still nothing

if anyone can help me figure this out id be much obliged. here is my code so far using excel 2007:Dim unit(1 To 2, 1 To 26) As String
Dim unitx As Integer
Dim unity As Integer
Dim rownum As Integer
Dim pt As PivotTable
Dim pi As PivotItem
Dim AllData As Range
Application.ScreenUpdating = True
Windows("CLABSI QDM.xls").Activate
Application.ScreenUpdating = True
Cells.Find(What:="*", After:=[b2], SearchDirection:=xlPrevious).Select
Range("B2", ActiveCell).Select
ActiveWorkbook.ActiveSheet.Names.Add Name:="TBL1", RefersTo:=Range("B2", ActiveCell).Select
MsgBox AllArea
MsgBox TBL1
Sheets.Add
Sheets("Sheet1").Select

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=TBL1, _
Version:=xlPivotTableVersion10).CreatePivotTable TableDestination:="Sheet1!R3C1", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10

Sheets("Sheet1").Select
Cells(3, 1).Select
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,214,925
Messages
6,122,303
Members
449,078
Latest member
nonnakkong

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