Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 791
Default Create a Pivottable in a macro

Hi, when I run a macro I would like to create a pivottable, however, the
data range changes each time I run the macro.

So the pivottable that I recorded only selects the original range

eg when the macro was recorded the range of data was from say A1 to Z1000
but next time I run the macro the data range could be A1 to Z2000.
Because the range ended at Z1000 when the macro was recorded, the pivot only
goes down to Z1000

I presume I need to somehow name a range and use that when calling the
pivottable but I'm not that advanced, can anyone help please?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default Create a Pivottable in a macro

Have a look at dynamic named ranges:
http://www.ozgrid.com/Excel/DynamicRanges.htm

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

Hi, when I run a macro I would like to create a pivottable, however, the
data range changes each time I run the macro.

So the pivottable that I recorded only selects the original range

eg when the macro was recorded the range of data was from say A1 to Z1000
but next time I run the macro the data range could be A1 to Z2000.
Because the range ended at Z1000 when the macro was recorded, the pivot only
goes down to Z1000

I presume I need to somehow name a range and use that when calling the
pivottable but I'm not that advanced, can anyone help please?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 791
Default Create a Pivottable in a macro

thanks, but how do I put that into a macro.
currently the code in the macro is like this:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Sheet1!R1C1:R3319C20").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable9", DefaultVersion:=xlPivotTableVersion10

I realise that Sheet1!R1C1:R3319C20 is what needs to be changed depending on
what the current range is but don't know the code to do it?
Any help is much appreciated.

"Dave F" wrote:

Have a look at dynamic named ranges:
http://www.ozgrid.com/Excel/DynamicRanges.htm

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

Hi, when I run a macro I would like to create a pivottable, however, the
data range changes each time I run the macro.

So the pivottable that I recorded only selects the original range

eg when the macro was recorded the range of data was from say A1 to Z1000
but next time I run the macro the data range could be A1 to Z2000.
Because the range ended at Z1000 when the macro was recorded, the pivot only
goes down to Z1000

I presume I need to somehow name a range and use that when calling the
pivottable but I'm not that advanced, can anyone help please?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default Create a Pivottable in a macro

You need to create the dynamic named range following the instructions at the
link I provide. Then, in place of the range you specify in your macro, place
the dynamic named range.

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

thanks, but how do I put that into a macro.
currently the code in the macro is like this:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Sheet1!R1C1:R3319C20").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable9", DefaultVersion:=xlPivotTableVersion10

I realise that Sheet1!R1C1:R3319C20 is what needs to be changed depending on
what the current range is but don't know the code to do it?
Any help is much appreciated.

"Dave F" wrote:

Have a look at dynamic named ranges:
http://www.ozgrid.com/Excel/DynamicRanges.htm

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

Hi, when I run a macro I would like to create a pivottable, however, the
data range changes each time I run the macro.

So the pivottable that I recorded only selects the original range

eg when the macro was recorded the range of data was from say A1 to Z1000
but next time I run the macro the data range could be A1 to Z2000.
Because the range ended at Z1000 when the macro was recorded, the pivot only
goes down to Z1000

I presume I need to somehow name a range and use that when calling the
pivottable but I'm not that advanced, can anyone help please?

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 791
Default Create a Pivottable in a macro

I understand that the code for my pivot in the macro is going to be

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
Myrange).CreatePivotTable TableDestination:="",
TableName:= "PivotTable9", DefaultVersion:=xlPivotTableVersion10

However, I don't know what the code would be to name the range in the first
place. Because the file that the macro is run on is downloaded from another
program, there are no ranges named and I want the macro to do that.



"Dave F" wrote:

You need to create the dynamic named range following the instructions at the
link I provide. Then, in place of the range you specify in your macro, place
the dynamic named range.

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

thanks, but how do I put that into a macro.
currently the code in the macro is like this:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Sheet1!R1C1:R3319C20").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable9", DefaultVersion:=xlPivotTableVersion10

I realise that Sheet1!R1C1:R3319C20 is what needs to be changed depending on
what the current range is but don't know the code to do it?
Any help is much appreciated.

"Dave F" wrote:

Have a look at dynamic named ranges:
http://www.ozgrid.com/Excel/DynamicRanges.htm

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

Hi, when I run a macro I would like to create a pivottable, however, the
data range changes each time I run the macro.

So the pivottable that I recorded only selects the original range

eg when the macro was recorded the range of data was from say A1 to Z1000
but next time I run the macro the data range could be A1 to Z2000.
Because the range ended at Z1000 when the macro was recorded, the pivot only
goes down to Z1000

I presume I need to somehow name a range and use that when calling the
pivottable but I'm not that advanced, can anyone help please?



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Create a Pivottable in a macro

Maybe (untested):

....SourceData:=worksheets("sheetnamehere").range( "MyRange")).createpivottable...

Michael wrote:

I understand that the code for my pivot in the macro is going to be

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
Myrange).CreatePivotTable TableDestination:="",
TableName:= "PivotTable9", DefaultVersion:=xlPivotTableVersion10

However, I don't know what the code would be to name the range in the first
place. Because the file that the macro is run on is downloaded from another
program, there are no ranges named and I want the macro to do that.

"Dave F" wrote:

You need to create the dynamic named range following the instructions at the
link I provide. Then, in place of the range you specify in your macro, place
the dynamic named range.

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

thanks, but how do I put that into a macro.
currently the code in the macro is like this:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Sheet1!R1C1:R3319C20").CreatePivotTable TableDestination:="",
TableName:= _
"PivotTable9", DefaultVersion:=xlPivotTableVersion10

I realise that Sheet1!R1C1:R3319C20 is what needs to be changed depending on
what the current range is but don't know the code to do it?
Any help is much appreciated.

"Dave F" wrote:

Have a look at dynamic named ranges:
http://www.ozgrid.com/Excel/DynamicRanges.htm

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

Hi, when I run a macro I would like to create a pivottable, however, the
data range changes each time I run the macro.

So the pivottable that I recorded only selects the original range

eg when the macro was recorded the range of data was from say A1 to Z1000
but next time I run the macro the data range could be A1 to Z2000.
Because the range ended at Z1000 when the macro was recorded, the pivot only
goes down to Z1000

I presume I need to somehow name a range and use that when calling the
pivottable but I'm not that advanced, can anyone help please?


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,886
Default Create a Pivottable in a macro

Hi Michael

to define your range

Dim Myrange as Range, lastrow as long, lastcol as long
lastrow = Cells(Rows.Count, 1).End(xlUp).row
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
Myrange = Range(Cells(1,1), Cells(lastrow, Lastcol))

If you know that it is always going to be column 20, then you need only
calculate the lastrow and use
Myrange = Range(Cells(1,1), Cells(lastrow, 20))

--
Regards

Roger Govier


"Michael" wrote in message
...
I understand that the code for my pivot in the macro is going to be

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
Myrange).CreatePivotTable TableDestination:="",
TableName:= "PivotTable9", DefaultVersion:=xlPivotTableVersion10

However, I don't know what the code would be to name the range in the
first
place. Because the file that the macro is run on is downloaded from
another
program, there are no ranges named and I want the macro to do that.



"Dave F" wrote:

You need to create the dynamic named range following the instructions
at the
link I provide. Then, in place of the range you specify in your
macro, place
the dynamic named range.

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Michael" wrote:

thanks, but how do I put that into a macro.
currently the code in the macro is like this:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"Sheet1!R1C1:R3319C20").CreatePivotTable
TableDestination:="",
TableName:= _
"PivotTable9", DefaultVersion:=xlPivotTableVersion10

I realise that Sheet1!R1C1:R3319C20 is what needs to be changed
depending on
what the current range is but don't know the code to do it?
Any help is much appreciated.

"Dave F" wrote:

Have a look at dynamic named ranges:
http://www.ozgrid.com/Excel/DynamicRanges.htm

Dave
--
A hint to posters: Specific, detailed questions are more likely
to be
answered than questions that provide no detail about your
problem.


"Michael" wrote:

Hi, when I run a macro I would like to create a pivottable,
however, the
data range changes each time I run the macro.

So the pivottable that I recorded only selects the original
range

eg when the macro was recorded the range of data was from say
A1 to Z1000
but next time I run the macro the data range could be A1 to
Z2000.
Because the range ended at Z1000 when the macro was recorded,
the pivot only
goes down to Z1000

I presume I need to somehow name a range and use that when
calling the
pivottable but I'm not that advanced, can anyone help please?



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
Can I create PivotTable formula using count of field not sum? Clip Excel Discussion (Misc queries) 0 November 7th 06 01:31 AM
Using a macro to create a macro in another workbook Gizmo63 Excel Worksheet Functions 2 May 15th 06 09:48 AM
Shadows of the Pivottable Field List while macro is running David P Excel Worksheet Functions 0 February 25th 05 07:11 PM
PivotTable Macro Reverts to Count Function LTofsrud Excel Worksheet Functions 4 February 8th 05 09:41 PM
PivotTable, Scenarios, Macro?? Dave Wilson New Users to Excel 4 December 18th 04 12:22 PM


All times are GMT +1. The time now is 02:46 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"