Pivot Table

S

solomon_monkey

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:=xlDatabase, SourceData:= _
"rng").CreatePivotTable TableDestination:= _
"'[Combined Filtered.xls]Pivot'!R5C1",
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
And it tells me 'Nooooooooooo'.
 
D

Debra Dalgleish

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:=xlDatabase, _
SourceData:=ws.Name & "!" & rng.Address) _
.CreatePivotTable TableDestination:="", _
TableName:="PivotTable1"
'======================

solomon_monkey said:
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:=xlDatabase, SourceData:= _
"rng").CreatePivotTable TableDestination:= _
"'[Combined Filtered.xls]Pivot'!R5C1",
TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
And it tells me 'Nooooooooooo'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top