Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default variable last cell in pivot table macro

I am trying to make the end of my pivot table range the last cell in the
worksheet (actually the next to last cell but I can't get to the last cell
yet). Anyone know the syntax for ths? Here's my current failed experiment,
substituting a range for the hard coded R1C1:R2000C41:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Cost Data'!Range(Selection,
ActiveCell.SpecialCells(xlLastCell))").CreatePivot Table TableDestination:="",
_

TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("PLINE")
.Orientation = xlRowField
.Position = 1
End With

Any thoughts are welcome.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default variable last cell in pivot table macro

dim mySource as range
with worksheets("cost data")
set mysource = .range("A1:E" & .cells(.rows.count,"A").row)
end with

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:= mysource.address(external:=true)).createPivotTable _
TableDestination:="".....

I used column A to find the last row and went to column E. Change that to what
you need.

Alan P wrote:

I am trying to make the end of my pivot table range the last cell in the
worksheet (actually the next to last cell but I can't get to the last cell
yet). Anyone know the syntax for ths? Here's my current failed experiment,
substituting a range for the hard coded R1C1:R2000C41:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Cost Data'!Range(Selection,
ActiveCell.SpecialCells(xlLastCell))").CreatePivot Table TableDestination:="",
_

TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("PLINE")
.Orientation = xlRowField
.Position = 1
End With

Any thoughts are welcome.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default variable last cell in pivot table macro

You could also use a dynamic range name that grows/contracts with your data.
This is nice if the pivottable's raw data could change (new rows added kind of
thing).

See Debra Dalgeish's site for some nice tips:
http://contextures.com/xlNames01.html#Dynamic

Dave Peterson wrote:

dim mySource as range
with worksheets("cost data")
set mysource = .range("A1:E" & .cells(.rows.count,"A").row)
end with

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:= mysource.address(external:=true)).createPivotTable _
TableDestination:="".....

I used column A to find the last row and went to column E. Change that to what
you need.

Alan P wrote:

I am trying to make the end of my pivot table range the last cell in the
worksheet (actually the next to last cell but I can't get to the last cell
yet). Anyone know the syntax for ths? Here's my current failed experiment,
substituting a range for the hard coded R1C1:R2000C41:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Cost Data'!Range(Selection,
ActiveCell.SpecialCells(xlLastCell))").CreatePivot Table TableDestination:="",
_

TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("PLINE")
.Orientation = xlRowField
.Position = 1
End With

Any thoughts are welcome.


--

Dave Peterson


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default variable last cell in pivot table macro

Dave,

Thanks, that worked nicely.

Alan

"Dave Peterson" wrote:

You could also use a dynamic range name that grows/contracts with your data.
This is nice if the pivottable's raw data could change (new rows added kind of
thing).

See Debra Dalgeish's site for some nice tips:
http://contextures.com/xlNames01.html#Dynamic

Dave Peterson wrote:

dim mySource as range
with worksheets("cost data")
set mysource = .range("A1:E" & .cells(.rows.count,"A").row)
end with

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:= mysource.address(external:=true)).createPivotTable _
TableDestination:="".....

I used column A to find the last row and went to column E. Change that to what
you need.

Alan P wrote:

I am trying to make the end of my pivot table range the last cell in the
worksheet (actually the next to last cell but I can't get to the last cell
yet). Anyone know the syntax for ths? Here's my current failed experiment,
substituting a range for the hard coded R1C1:R2000C41:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Cost Data'!Range(Selection,
ActiveCell.SpecialCells(xlLastCell))").CreatePivot Table TableDestination:="",
_

TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("PLINE")
.Orientation = xlRowField
.Position = 1
End With

Any thoughts are welcome.


--

Dave Peterson


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Entering Variable in a Pivot Table flyer27 Excel Discussion (Misc queries) 0 March 13th 07 03:05 PM
selecting variable rows in a macro that creates a pivot table amarch00 Excel Programming 1 May 12th 05 03:43 PM
Pivot Table variable range La Durande Excel Programming 1 October 18th 04 08:42 PM
Im so close. Need variable range for the pivot table Loren[_2_] Excel Programming 1 October 5th 04 10:53 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 04:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"