ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pivot Table (https://www.excelbanter.com/excel-programming/319511-pivot-table.html)

solomon_monkey

Pivot Table
 
Can I write a macro for a pivot table defining the range as

Range("A3:K3", Selection.End(xlDown)).Select

I'm trying with

Dim rng As Range
Range("A3:K3", Selection.End(xlDown)).Select

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"rng").CreatePivotTable TableDestination:= _
"'[Combined Filtered.xls]Pivot'!R5C1",
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
And it tells me 'Nooooooooooo'.


Debra Dalgleish

Pivot Table
 
You could use the current region of cell A3. For example:

'=========================
Dim ws As Worksheet
Dim rng As Range
Set ws = Sheets("Sheet1")
Set rng = ws.Range("A3").CurrentRegion

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, _
SourceData:=ws.Name & "!" & rng.Address) _
.CreatePivotTable TableDestination:="", _
TableName:="PivotTable1"
'======================

solomon_monkey wrote:
Can I write a macro for a pivot table defining the range as

Range("A3:K3", Selection.End(xlDown)).Select

I'm trying with

Dim rng As Range
Range("A3:K3", Selection.End(xlDown)).Select

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"rng").CreatePivotTable TableDestination:= _
"'[Combined Filtered.xls]Pivot'!R5C1",
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
And it tells me 'Nooooooooooo'.



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html



All times are GMT +1. The time now is 01:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com