Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Selecting current range for pivot macro

I'm trying to write a macro to create a standard pivot from a report
and need some help with defining the range.

I've recorded the actions that I want using an example of the data.
It all appears to be fine and reasonably easy (if sometimes feeling
long winded), except the range selection at the start.

The start of the recorded macro looks like this...

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Base Data Report'!R1C1:R244C44").CreatePivotTable _
TableDestination:="", TableName:="PivotTable1",
DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = False
.RowGrand = False
End With

I'm presuming that VBA doesn't recognise the normal "select current
range based on current cell" action of the Pivot Table wizard. In the
above, it's explicitly defined the range even though I didn't actually
have to think about that when recording.

How do I replicate the "select current range..." action for a generic
macro (because the number of records will vary each time)?

I presume the best way would be to define a variable, use some method
to push the current range into the variable, and then point the pivot
at it. But I don't know how.

Or maybe, since the columns will stay the same, I should look at
counting the rows and defining the range that way (Offset comes to
mind, but I've also read mentions of the Resize function - but, if it
is applicable, I can't find a clear explanation of how.)

Any help will be greatly appreciated.

ta
Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Selecting current range for pivot macro

You need to supply a range for your data argument

The easiest way to do this is to use the currentregion method of the range
object.
Assuming your data is in a sheet called 'Data'. starting in cell A1 the
arguement would be:

sheets("Data").cells(1,1).currentregion


"Math" wrote:

I'm trying to write a macro to create a standard pivot from a report
and need some help with defining the range.

I've recorded the actions that I want using an example of the data.
It all appears to be fine and reasonably easy (if sometimes feeling
long winded), except the range selection at the start.

The start of the recorded macro looks like this...

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Base Data Report'!R1C1:R244C44").CreatePivotTable _
TableDestination:="", TableName:="PivotTable1",
DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = False
.RowGrand = False
End With

I'm presuming that VBA doesn't recognise the normal "select current
range based on current cell" action of the Pivot Table wizard. In the
above, it's explicitly defined the range even though I didn't actually
have to think about that when recording.

How do I replicate the "select current range..." action for a generic
macro (because the number of records will vary each time)?

I presume the best way would be to define a variable, use some method
to push the current range into the variable, and then point the pivot
at it. But I don't know how.

Or maybe, since the columns will stay the same, I should look at
counting the rows and defining the range that way (Offset comes to
mind, but I've also read mentions of the Resize function - but, if it
is applicable, I can't find a clear explanation of how.)

Any help will be greatly appreciated.

ta
Matt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Selecting current range for pivot macro

Thanks.

How would I fit that into

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Base Data Report'!R1C1:R244C44").CreatePivotTable _
TableDestination:="", TableName:="PivotTable1",

?

Thanks again.

On 4 Feb, 14:14, DomThePom
wrote:
You need to supply a range for your data argument

The easiest way to do this is to use the currentregion method of the range
object.
Assuming your data is in a sheet called 'Data'. starting in cell A1 the
arguement would be:

sheets("Data").cells(1,1).currentregion



"Math" wrote:
I'm trying to write a macro to create a standard pivot from a report
and need some help with defining the range.


I've recorded the actions that I want using an example of the data.
It all appears to be fine and reasonably easy (if sometimes feeling
long winded), except the range selection at the start.


The start of the recorded macro looks like this...


ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
* * * * "'Base Data Report'!R1C1:R244C44").CreatePivotTable _
* * * * TableDestination:="", TableName:="PivotTable1",
DefaultVersion:= _
* * * * xlPivotTableVersion10
* * ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
* * ActiveSheet.Cells(3, 1).Select
* * With ActiveSheet.PivotTables("PivotTable1")
* * * * .ColumnGrand = False
* * * * .RowGrand = False
* * End With


I'm presuming that VBA doesn't recognise the normal "select current
range based on current cell" action of the Pivot Table wizard. *In the
above, it's explicitly defined the range even though I didn't actually
have to think about that when recording.


How do I replicate the "select current range..." action for a generic
macro (because the number of records will vary each time)?


I presume the best way would be to define a variable, use some method
to push the current range into the variable, and then point the pivot
at it. *But I don't know how.


Or maybe, since the columns will stay the same, I should look at
counting the rows and defining the range that way (Offset comes to
mind, but I've also read mentions of the Resize function - but, if it
is applicable, I can't find a clear explanation of how.)


Any help will be greatly appreciated.


ta
Matt- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Selecting current range for pivot macro

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
sheets("Base Data
Report").cells(1,1).currentregion).CreatePivotTabl e _
TableDestination:="", TableName:="PivotTable1

Try this but if you still have trouble.....

I use the PivotTableWizard method of the sheet object which is a little less
complicated.

dim sht as worksheet
dim pvt as PivotTable
dim rngData as range

set rng = sheets("Base Data Report").cells(1,1).currentregion
set sht = activeworkbook.sheets.add
set pvt = sht.PivotTableWizard(xlDatabase, rngData, , "PivotTable1")

"Math" wrote:

Thanks.

How would I fit that into

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Base Data Report'!R1C1:R244C44").CreatePivotTable _
TableDestination:="", TableName:="PivotTable1",

?

Thanks again.

On 4 Feb, 14:14, DomThePom
wrote:
You need to supply a range for your data argument

The easiest way to do this is to use the currentregion method of the range
object.
Assuming your data is in a sheet called 'Data'. starting in cell A1 the
arguement would be:

sheets("Data").cells(1,1).currentregion



"Math" wrote:
I'm trying to write a macro to create a standard pivot from a report
and need some help with defining the range.


I've recorded the actions that I want using an example of the data.
It all appears to be fine and reasonably easy (if sometimes feeling
long winded), except the range selection at the start.


The start of the recorded macro looks like this...


ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Base Data Report'!R1C1:R244C44").CreatePivotTable _
TableDestination:="", TableName:="PivotTable1",
DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = False
.RowGrand = False
End With


I'm presuming that VBA doesn't recognise the normal "select current
range based on current cell" action of the Pivot Table wizard. In the
above, it's explicitly defined the range even though I didn't actually
have to think about that when recording.


How do I replicate the "select current range..." action for a generic
macro (because the number of records will vary each time)?


I presume the best way would be to define a variable, use some method
to push the current range into the variable, and then point the pivot
at it. But I don't know how.


Or maybe, since the columns will stay the same, I should look at
counting the rows and defining the range that way (Offset comes to
mind, but I've also read mentions of the Resize function - but, if it
is applicable, I can't find a clear explanation of how.)


Any help will be greatly appreciated.


ta
Matt- Hide quoted text -


- Show quoted text -



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Selecting current range for pivot macro

Ah, wonderful. Thankyou :)

On 4 Feb, 17:01, DomThePom
wrote:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
* * * * sheets("Base Data
Report").cells(1,1).currentregion).CreatePivotTabl e _
* * * * TableDestination:="", TableName:="PivotTable1

Try this but if you still have trouble.....

I use the PivotTableWizard method of the sheet object which is a little less
complicated.

dim sht as worksheet
dim pvt as PivotTable
dim rngData as range

set rng = sheets("Base Data Report").cells(1,1).currentregion
set sht = activeworkbook.sheets.add
set pvt *= sht.PivotTableWizard(xlDatabase, rngData, , "PivotTable1")



"Math" wrote:
Thanks.


How would I fit that into


ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
* * * * "'Base Data Report'!R1C1:R244C44").CreatePivotTable _
* * * * TableDestination:="", TableName:="PivotTable1",


?


Thanks again.


On 4 Feb, 14:14, DomThePom
wrote:
You need to supply a range for your data argument


The easiest way to do this is to use the currentregion method of the range
object.
Assuming your data is in a sheet called 'Data'. starting in cell A1 the
arguement would be:


sheets("Data").cells(1,1).currentregion


"Math" wrote:
I'm trying to write a macro to create a standard pivot from a report
and need some help with defining the range.


I've recorded the actions that I want using an example of the data.
It all appears to be fine and reasonably easy (if sometimes feeling
long winded), except the range selection at the start.


The start of the recorded macro looks like this...


ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
* * * * "'Base Data Report'!R1C1:R244C44").CreatePivotTable _
* * * * TableDestination:="", TableName:="PivotTable1",
DefaultVersion:= _
* * * * xlPivotTableVersion10
* * ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
* * ActiveSheet.Cells(3, 1).Select
* * With ActiveSheet.PivotTables("PivotTable1")
* * * * .ColumnGrand = False
* * * * .RowGrand = False
* * End With


I'm presuming that VBA doesn't recognise the normal "select current
range based on current cell" action of the Pivot Table wizard. *In the
above, it's explicitly defined the range even though I didn't actually
have to think about that when recording.


How do I replicate the "select current range..." action for a generic
macro (because the number of records will vary each time)?


I presume the best way would be to define a variable, use some method
to push the current range into the variable, and then point the pivot
at it. *But I don't know how.


Or maybe, since the columns will stay the same, I should look at
counting the rows and defining the range that way (Offset comes to
mind, but I've also read mentions of the Resize function - but, if it
is applicable, I can't find a clear explanation of how.)


Any help will be greatly appreciated.


ta
Matt- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




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
Selecting the current month using a macro on a pivot table Newbee Excel Discussion (Misc queries) 3 November 12th 06 07:10 PM
Selecting a range of values on pivot table attribute with a macro Ryan Hartnett Excel Discussion (Misc queries) 1 October 24th 06 10:21 PM
Macro €“ select all cells in current range Mary Ann Excel Discussion (Misc queries) 3 December 12th 05 07:19 AM
Selecting next drop down item in pivot table with a macro ??? Keilan Knight Excel Programming 2 February 22nd 05 11:30 AM
Selecting a range composed of current region + 2 rows Bruce Roberson[_5_] Excel Programming 2 October 27th 04 03:00 PM


All times are GMT +1. The time now is 03:41 AM.

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

About Us

"It's about Microsoft Excel"