Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default (repost) Dynamically creating pivot tables from page-field list

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default (repost) Dynamically creating pivot tables from page-field list

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values


What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default (repost) Dynamically creating pivot tables from page-field lis

H Tom,

Well, I also posted a similar question a number of months ago when I wanted
to parse employ names from a column in my summary sheet to individually
macro-generated worksheets. This worked fine. Now I have another project, and
I am using the same principle, but this time, I need to parse a list of codes
from Column C into individual worksheets. The only difference is that I each
worksheet is a pivot table whose page filter is one of the values in my
Column C. I'm thinking that this might be too complex. Instead, perhaps I can
pre-configure pivot tables and have their page filter values linked to
drop-down selections on my Summary Sheet. Perhaps a radial button can unhide
a pivot table when the user has selected a value for its page filter.... What
do you think?
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values


What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default (repost) Dynamically creating pivot tables from page-field lis

By the way, I use the term "parse" to mean to create a worksheet with a pivot
table that uses one of the values in column c on my Summary Sheet.

--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"klysell" wrote:

H Tom,

Well, I also posted a similar question a number of months ago when I wanted
to parse employ names from a column in my summary sheet to individually
macro-generated worksheets. This worked fine. Now I have another project, and
I am using the same principle, but this time, I need to parse a list of codes
from Column C into individual worksheets. The only difference is that I each
worksheet is a pivot table whose page filter is one of the values in my
Column C. I'm thinking that this might be too complex. Instead, perhaps I can
pre-configure pivot tables and have their page filter values linked to
drop-down selections on my Summary Sheet. Perhaps a radial button can unhide
a pivot table when the user has selected a value for its page filter.... What
do you think?
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values


What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default (repost) Dynamically creating pivot tables from page-field lis

After rereading your original and then this one, I think the original sounds
more satisfying than a huge workbook with many sheets with pivot tables.
Have a template pivot table already linked to your data. When a user selects
a value from the dropdown on the summary sheet, then copy this pivot table
template sheet and set the pagefilter.

so you could use the change event of the summary sheet. Right click on the
summary sheet tab and select view code. Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pi As PivotItem
If Target.count 1 then exit sub
If Target.Column = 3 or Target.column = 4 then

set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count))

it Target.column = 3 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Name")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
elseif Target.Column = 4 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Company")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
end if
sh.Activate
End if
End Sub

You would need to adjust it to match the pivot table name and the field
names. The template pivot table would have page fields for both possible
selections - or you could make the macro more extensive in rearranging the
table.

Of course I could have misunderstood.

--
Regards,
Tom Ogilvy

"klysell" wrote:

H Tom,

Well, I also posted a similar question a number of months ago when I wanted
to parse employ names from a column in my summary sheet to individually
macro-generated worksheets. This worked fine. Now I have another project, and
I am using the same principle, but this time, I need to parse a list of codes
from Column C into individual worksheets. The only difference is that I each
worksheet is a pivot table whose page filter is one of the values in my
Column C. I'm thinking that this might be too complex. Instead, perhaps I can
pre-configure pivot tables and have their page filter values linked to
drop-down selections on my Summary Sheet. Perhaps a radial button can unhide
a pivot table when the user has selected a value for its page filter.... What
do you think?
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values


What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default (repost) Dynamically creating pivot tables from page-field lis

Hi Tom,

Thanks so much! I'll mull over what you sent me using my virgin-VBA
understanding and see if I can integrate it.

All the best,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

After rereading your original and then this one, I think the original sounds
more satisfying than a huge workbook with many sheets with pivot tables.
Have a template pivot table already linked to your data. When a user selects
a value from the dropdown on the summary sheet, then copy this pivot table
template sheet and set the pagefilter.

so you could use the change event of the summary sheet. Right click on the
summary sheet tab and select view code. Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pi As PivotItem
If Target.count 1 then exit sub
If Target.Column = 3 or Target.column = 4 then

set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count))

it Target.column = 3 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Name")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
elseif Target.Column = 4 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Company")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
end if
sh.Activate
End if
End Sub

You would need to adjust it to match the pivot table name and the field
names. The template pivot table would have page fields for both possible
selections - or you could make the macro more extensive in rearranging the
table.

Of course I could have misunderstood.

--
Regards,
Tom Ogilvy

"klysell" wrote:

H Tom,

Well, I also posted a similar question a number of months ago when I wanted
to parse employ names from a column in my summary sheet to individually
macro-generated worksheets. This worked fine. Now I have another project, and
I am using the same principle, but this time, I need to parse a list of codes
from Column C into individual worksheets. The only difference is that I each
worksheet is a pivot table whose page filter is one of the values in my
Column C. I'm thinking that this might be too complex. Instead, perhaps I can
pre-configure pivot tables and have their page filter values linked to
drop-down selections on my Summary Sheet. Perhaps a radial button can unhide
a pivot table when the user has selected a value for its page filter.... What
do you think?
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values

What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default (repost) Dynamically creating pivot tables from page-field lis

Tom,

Why is the code on the fifth line,
"set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count))"
giving me a compile error (missing "=")

TIA



--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

After rereading your original and then this one, I think the original sounds
more satisfying than a huge workbook with many sheets with pivot tables.
Have a template pivot table already linked to your data. When a user selects
a value from the dropdown on the summary sheet, then copy this pivot table
template sheet and set the pagefilter.

so you could use the change event of the summary sheet. Right click on the
summary sheet tab and select view code. Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pi As PivotItem
If Target.count 1 then exit sub
If Target.Column = 3 or Target.column = 4 then

set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count))

it Target.column = 3 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Name")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
elseif Target.Column = 4 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Company")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
end if
sh.Activate
End if
End Sub

You would need to adjust it to match the pivot table name and the field
names. The template pivot table would have page fields for both possible
selections - or you could make the macro more extensive in rearranging the
table.

Of course I could have misunderstood.

--
Regards,
Tom Ogilvy

"klysell" wrote:

H Tom,

Well, I also posted a similar question a number of months ago when I wanted
to parse employ names from a column in my summary sheet to individually
macro-generated worksheets. This worked fine. Now I have another project, and
I am using the same principle, but this time, I need to parse a list of codes
from Column C into individual worksheets. The only difference is that I each
worksheet is a pivot table whose page filter is one of the values in my
Column C. I'm thinking that this might be too complex. Instead, perhaps I can
pre-configure pivot tables and have their page filter values linked to
drop-down selections on my Summary Sheet. Perhaps a radial button can unhide
a pivot table when the user has selected a value for its page filter.... What
do you think?
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values

What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default (repost) Dynamically creating pivot tables from page-field lis

I used:
"Sheets("PIV_Template").Copy After:=Worksheets(Worksheets.Count)"
in place of:
"set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count)) "
and I no longer got the compile error message. Does this new code supplant
the old code without changing the purpose?

--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

After rereading your original and then this one, I think the original sounds
more satisfying than a huge workbook with many sheets with pivot tables.
Have a template pivot table already linked to your data. When a user selects
a value from the dropdown on the summary sheet, then copy this pivot table
template sheet and set the pagefilter.

so you could use the change event of the summary sheet. Right click on the
summary sheet tab and select view code. Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pi As PivotItem
If Target.count 1 then exit sub
If Target.Column = 3 or Target.column = 4 then

set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count))

it Target.column = 3 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Name")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
elseif Target.Column = 4 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Company")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
end if
sh.Activate
End if
End Sub

You would need to adjust it to match the pivot table name and the field
names. The template pivot table would have page fields for both possible
selections - or you could make the macro more extensive in rearranging the
table.

Of course I could have misunderstood.

--
Regards,
Tom Ogilvy

"klysell" wrote:

H Tom,

Well, I also posted a similar question a number of months ago when I wanted
to parse employ names from a column in my summary sheet to individually
macro-generated worksheets. This worked fine. Now I have another project, and
I am using the same principle, but this time, I need to parse a list of codes
from Column C into individual worksheets. The only difference is that I each
worksheet is a pivot table whose page filter is one of the values in my
Column C. I'm thinking that this might be too complex. Instead, perhaps I can
pre-configure pivot tables and have their page filter values linked to
drop-down selections on my Summary Sheet. Perhaps a radial button can unhide
a pivot table when the user has selected a value for its page filter.... What
do you think?
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values

What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default (repost) Dynamically creating pivot tables from page-field lis

Here is a fix for that typo and one or two others. This compiles, but I
don't have a pivot table set up to test it with. If you need me to do that,
let me know.



Private Sub Worksheet_Change(ByVal Target As Range)
Dim pi As PivotItem
Dim sh As Worksheet
If Target.Count 1 Then Exit Sub
If Target.Column = 3 Or Target.Column = 4 Then

Set sh = Worksheets("PIV_Template").Copy(After:=Worksheets( Worksheets.Count))

If Target.Column = 3 Then
With sh.PivotTables("PivotTable1") _
.PivotFields("Name")
For Each pi In .PivotItems
If LCase(pi.Value) = LCase(Target.Value) Then
.CurrentPage = pi.Value
End If
Next
End With
ElseIf Target.Column = 4 Then
With sh.PivotTables("PivotTable1") _
.PivotFields("Company")
For Each pi In .PivotItems
If LCase(pi.Value) = LCase(Target.Value) Then
.CurrentPage = pi.Value
End If
Next
End With
End If
sh.Activate
End If
End Sub

--
Regards,
Tom Ogilvy


"klysell" wrote:

I used:
"Sheets("PIV_Template").Copy After:=Worksheets(Worksheets.Count)"
in place of:
"set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count)) "
and I no longer got the compile error message. Does this new code supplant
the old code without changing the purpose?

--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

After rereading your original and then this one, I think the original sounds
more satisfying than a huge workbook with many sheets with pivot tables.
Have a template pivot table already linked to your data. When a user selects
a value from the dropdown on the summary sheet, then copy this pivot table
template sheet and set the pagefilter.

so you could use the change event of the summary sheet. Right click on the
summary sheet tab and select view code. Put in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pi As PivotItem
If Target.count 1 then exit sub
If Target.Column = 3 or Target.column = 4 then

set worksheets("PIV_Template").Copy( After:=Worksheets(worksheets.count))

it Target.column = 3 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Name")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
elseif Target.Column = 4 then
With sh.PivotTables("PivotTable1") _
.PivotFields("Company")
For Each pi In .PivotItems
If lcase(pi.Value) = lcase(target.value) Then
.CurrentPage = pi.Value
End If
Next
End With
end if
sh.Activate
End if
End Sub

You would need to adjust it to match the pivot table name and the field
names. The template pivot table would have page fields for both possible
selections - or you could make the macro more extensive in rearranging the
table.

Of course I could have misunderstood.

--
Regards,
Tom Ogilvy

"klysell" wrote:

H Tom,

Well, I also posted a similar question a number of months ago when I wanted
to parse employ names from a column in my summary sheet to individually
macro-generated worksheets. This worked fine. Now I have another project, and
I am using the same principle, but this time, I need to parse a list of codes
from Column C into individual worksheets. The only difference is that I each
worksheet is a pivot table whose page filter is one of the values in my
Column C. I'm thinking that this might be too complex. Instead, perhaps I can
pre-configure pivot tables and have their page filter values linked to
drop-down selections on my Summary Sheet. Perhaps a radial button can unhide
a pivot table when the user has selected a value for its page filter.... What
do you think?
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Tom Ogilvy" wrote:

Seems like I have seen this question posted before. If you didn't get a
response, it generally means that the question isn't understood (or less
likely, it is not doable or to complex to attempt an answer (someone wants a
free project done for them)).

I would guess your question is not understood. For me:

So the question you ask is:

I just need the VBA code that will do the parsing of these values

What do you mean by "these values"? What do you mean by parsing?

--
Regards,
Tom Ogilvy


"klysell" wrote:

Hi,

I have two adjacent columns, occuping Column C and D (range C15:D100), in my
summary sheet. The user selects values from a drop-down list in both columns,
with one OR the other value in a pair being selected (and the other remaining
blank).

I would like to dynamically generate pivot tables based on data from my
"PivotData" sheet, according to a pre-arranged PT format, with either the
value in Column C OR Column D forming the Pivot table page filter.
Essentially I'd like a macro to create new worksheets, each with a new pivot
table using a page filter from one or the other value of user-chosen,
drop-down values in Column C or D.

Perhaps once the user has selected values in Column C and D (e.g. for row
15, either C15 or D15 is filled with data using a data validation function),
a macro will parse these values in separate worksheets and a pivot table is
generated using this values in Columns C and D as page filters.

I already have a pivot table designed, and I know that I could turn on the
macro recorder and use this code when dynamically generating all the pivot
tables. I could then refine this recorded macro to be more efficient (i.e.
using knowledge gained from John Walkenbach's Power Programming with VBA
book). I just need the VBA code that will do the parsing of these values.

What would be my best route to solve this problem?

Thanks in advance,
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557

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
(2) Pivot Tables on the Same Sheet to have the same Page Field Havenstar Excel Discussion (Misc queries) 0 March 11th 09 01:24 PM
Creating Pivot tables dynamically from page filter values summary klysell Excel Programming 0 July 9th 07 09:16 PM
Pivot Table Page Field (Repost) Barb Reinhardt Excel Programming 2 July 9th 07 01:48 PM
Page field in pivot tables Ekazakoff Excel Discussion (Misc queries) 3 December 1st 06 04:23 AM
Multiple Pivot Tables with single Page Field cscribner Excel Discussion (Misc queries) 1 May 26th 05 12:26 AM


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