<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Referencing Pivot Table Ranges in VBA</title>
	<atom:link href="http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/feed/" rel="self" type="application/rss+xml" />
	<link>http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/</link>
	<description>Peltier Tech Excel Charts and Programming Blog</description>
	<lastBuildDate>Wed, 23 May 2012 11:03:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Miguel</title>
		<link>http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/comment-page-3/#comment-217535</link>
		<dc:creator>Miguel</dc:creator>
		<pubDate>Tue, 08 May 2012 09:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2310#comment-217535</guid>
		<description>Hi, reading the post on Pivot tables now realize that this is something I could use to great effect.

However I need some help please, the code below is recoreded and I have modifid the way it renames the sheets, after selecting the data in each cell in the Piviot table Range in the totals column on PT.

The problem that I have the report I run the Macro on changes every time its run and errors occurs on the Pt.RowRange this may have 10 row or 20 rows depending on the data.

Is the a away to do the same function that I have recorded and not stop the Macro from working by selecting all the cells in column B and not include the grandtotal row?

Your guidince would be appriciated.



Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        &quot;Furniture Monthly Overstock!R1C1:R653C14&quot;, Version:=xlPivotTableVersion10). _
        CreatePivotTable TableDestination:=&quot;Sheet1!R3C1&quot;, TableName:=&quot;PivotTable1&quot; _
        , DefaultVersion:=xlPivotTableVersion10
    Sheets(&quot;Sheet1&quot;).Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables(&quot;PivotTable1&quot;).PivotFields(&quot;Site&quot;)
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables(&quot;PivotTable1&quot;).PivotFields(&quot;Product Code&quot;)
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables(&quot;PivotTable1&quot;).AddDataField ActiveSheet.PivotTables( _
        &quot;PivotTable1&quot;).PivotFields(&quot;Product Code&quot;), &quot;Count of Product Code&quot;, xlCount
    RANGE(&quot;B5&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B6&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B7&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B8&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B9&quot;).Select
    Selection.ShowDetail = True
   ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B10&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B11&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B12&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B13&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B14&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B15&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B16&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B17&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B18&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B19&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B20&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B21&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B22&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B23&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B24&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
    Sheets(&quot;Sheet1&quot;).Select
    RANGE(&quot;B25&quot;).Select
    Selection.ShowDetail = True
    ActiveSheet.Name = &quot;SITE &quot; &amp; RANGE(&quot;E2&quot;).Value
     ActiveWindow.TabRatio = 0.8
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    Sheets(&quot;Furniture Monthly Overstock&quot;).Select
    Sheets(&quot;Furniture Monthly Overstock&quot;).Move Before:=Sheets(1)
     Sheets(&quot;Sheet1&quot;).Move Before:=Sheets(2)</description>
		<content:encoded><![CDATA[<p>Hi, reading the post on Pivot tables now realize that this is something I could use to great effect.</p>
<p>However I need some help please, the code below is recoreded and I have modifid the way it renames the sheets, after selecting the data in each cell in the Piviot table Range in the totals column on PT.</p>
<p>The problem that I have the report I run the Macro on changes every time its run and errors occurs on the Pt.RowRange this may have 10 row or 20 rows depending on the data.</p>
<p>Is the a away to do the same function that I have recorded and not stop the Macro from working by selecting all the cells in column B and not include the grandtotal row?</p>
<p>Your guidince would be appriciated.</p>
<p>Sheets.Add<br />
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _<br />
        &#8220;Furniture Monthly Overstock!R1C1:R653C14&#8243;, Version:=xlPivotTableVersion10). _<br />
        CreatePivotTable TableDestination:=&#8221;Sheet1!R3C1&#8243;, TableName:=&#8221;PivotTable1&#8243; _<br />
        , DefaultVersion:=xlPivotTableVersion10<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    Cells(3, 1).Select<br />
    With ActiveSheet.PivotTables(&#8220;PivotTable1&#8243;).PivotFields(&#8220;Site&#8221;)<br />
        .Orientation = xlRowField<br />
        .Position = 1<br />
    End With<br />
    With ActiveSheet.PivotTables(&#8220;PivotTable1&#8243;).PivotFields(&#8220;Product Code&#8221;)<br />
        .Orientation = xlRowField<br />
        .Position = 2<br />
    End With<br />
    ActiveSheet.PivotTables(&#8220;PivotTable1&#8243;).AddDataField ActiveSheet.PivotTables( _<br />
        &#8220;PivotTable1&#8243;).PivotFields(&#8220;Product Code&#8221;), &#8220;Count of Product Code&#8221;, xlCount<br />
    RANGE(&#8220;B5&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B6&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B7&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B8&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B9&#8243;).Select<br />
    Selection.ShowDetail = True<br />
   ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B10&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B11&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B12&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B13&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B14&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B15&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B16&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B17&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B18&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B19&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B20&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B21&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B22&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B23&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B24&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
    Sheets(&#8220;Sheet1&#8243;).Select<br />
    RANGE(&#8220;B25&#8243;).Select<br />
    Selection.ShowDetail = True<br />
    ActiveSheet.Name = &#8220;SITE &#8221; &amp; RANGE(&#8220;E2&#8243;).Value<br />
     ActiveWindow.TabRatio = 0.8<br />
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst<br />
    Sheets(&#8220;Furniture Monthly Overstock&#8221;).Select<br />
    Sheets(&#8220;Furniture Monthly Overstock&#8221;).Move Before:=Sheets(1)<br />
     Sheets(&#8220;Sheet1&#8243;).Move Before:=Sheets(2)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Glancy</title>
		<link>http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/comment-page-3/#comment-213434</link>
		<dc:creator>Doug Glancy</dc:creator>
		<pubDate>Thu, 26 Apr 2012 14:06:00 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2310#comment-213434</guid>
		<description>@ Jeff, I forgot about PivotTable.VisibleFields, which you use here and which doesn&#039;t cause me the same problem with DataFields that I mentioned above and in my post.</description>
		<content:encoded><![CDATA[<p>@ Jeff, I forgot about PivotTable.VisibleFields, which you use here and which doesn&#8217;t cause me the same problem with DataFields that I mentioned above and in my post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Weir</title>
		<link>http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/comment-page-3/#comment-213341</link>
		<dc:creator>Jeff Weir</dc:creator>
		<pubDate>Thu, 26 Apr 2012 08:34:39 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2310#comment-213341</guid>
		<description>@Doug...Ha...I didn&#039;t realise you were the person behind yoursumbuddy, and that you&#039;ve just posted code to do the same over at your blog. Doh!</description>
		<content:encoded><![CDATA[<p>@Doug&#8230;Ha&#8230;I didn&#8217;t realise you were the person behind yoursumbuddy, and that you&#8217;ve just posted code to do the same over at your blog. Doh!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Weir</title>
		<link>http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/comment-page-3/#comment-213339</link>
		<dc:creator>Jeff Weir</dc:creator>
		<pubDate>Thu, 26 Apr 2012 08:28:52 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2310#comment-213339</guid>
		<description>No problem. Probably worth mentioning that the reason that I want to store PivotTable items in dictionary objects when they exist as collections already. Among other things, I want to be able to create &#039;Custom View&#039; functionality that works for pivottables, so that the user can save their newly filtered pivottable, and at any time easily return to it, filters already in place. 

For anyone else reading along who&#039;s not familiar with custom views, as per http://www.ozgrid.com/Excel/AutoFilters_2.htm custom views allow you to do this for autofilter collections by uing View&gt;Custom Views and click the Add button (provided you don&#039;t have any excel 2007/10 tables in your document - for some reason these conflict with the Custom View functionality, which is a damn stupid move on part of MS) . Give your view a name and make sure you have a tick next to Hidden rows, columns and filter settings. This is a must to retain all the settings. Click OK. You can then call up your filtered list as a Custom View by going to View&gt;Custom Views, clicking on the name of your view and selecting the Show button.

I want to do something similar with pivottables. So what I want to do is save my pivottabel settings somewhere (likely a hidden sheet), so that I can recreate it at the push of a button. I think the jagged array approach is going to be the best way to do this in terms of  flexibility .. I can easily add further dimensions to hold other data regarding pivotfields, such as hidden items, number formats, whatever.

Whereas with the collection/dictionary approach I would require a separate collection/dictionaries for each subsequent type of attribute, as far as I know. Also with collections, I don&#039;t believe you can retrieve the key, so I won&#039;t neccessarily know which set of filter items go with which pivot field. Although I could easily get around this by storing the subdictionary (i.e. the one that contains the pivotitems) in say the 2 element Variant Array; with the field name stored in Variant_Array(0) and the dictionary stored in Variant_Array(1).

Note that this is a dictionary stored within a jagged array stored within a dictionary!

Also, in case anyone is interested, here&#039;s my code to churn out named ranges from pivotfields:

&lt;code&gt;

Sub Make_Names()
    Dim pt As PivotTable
    Dim pf As PivotField
    Dim wks As Worksheet
    
    Set wks = ActiveSheet
    Set pt = wks.PivotTables(1)
       
For Each pf In pt.VisibleFields

With ActiveWorkbook.Names
   .Add Name:=Fix_Name(pf.Name), RefersTo:=&quot;=&quot; &amp; pf.DataRange.Address
    End With
Next pf

End Sub

Public Function Fix_Name(sName As String) As String
&#039;   This code was from Craig Hatmaker. Google &#039;Beyond Excel&#039; for more info
&#039;   Description:Conforms a string so it can be used as a name

&#039;   Parameters: sName       String to be conformed

&#039;   Example:    sColumnName = Fix_Name(&quot;1st deposit %&quot;)

&#039;     Date   Ini Modification
&#039;   11/02/10 CWH Initial Programming
&#039;   11/20/10 CWH Used &quot;Like&quot; operator

    &#039;If Not DebugMode Then On Error GoTo ErrHandler
    Fix_Name = sName
    
    Dim i As Integer
            
   &#039;Substitute special invalid characters w/standard abbreviations
    sName = Replace(sName, &quot;#&quot;, &quot;_NUM&quot;)
    sName = Replace(sName, &quot;$&quot;, &quot;_AMT&quot;)
    sName = Replace(sName, &quot;%&quot;, &quot;_PCT&quot;)
    sName = Replace(sName, &quot;-&quot;, &quot;.&quot;)
    sName = Replace(sName, &quot;,&quot;, &quot;-&quot;)
    sName = Replace(sName, &quot; &quot;, &quot;_&quot;)
    
   &#039;Get rid of all other illegal characters
    i = 1
    Do While i &lt;= Len(sName)
        If Not Mid(sName, i, 1) Like &quot;[A-Z,a-z,0-9,.,_,\]&quot; Then _
            sName = Left(sName, i - 1) &amp; Right(sName, Len(sName) - i)
        i = i + 1
    Loop
    
   &#039;First Character cannot be numeric &amp; result cannot look like cell ref.
    If IsNumeric(Left(sName, 1)) Or sName Like &quot;[A-Z]#&quot; Then _
        sName = &quot;_&quot; &amp; sName

    Fix_Name = sName

ErrHandler:
    
    If Err.Number  0 Then MsgBox _
        &quot;Fix_Name - Error#&quot; &amp; Err.Number &amp; vbCrLf &amp; _
        Err.Description, vbCritical, &quot;Error&quot;, Err.HelpFile, Err.HelpContext
    On Error GoTo 0

End Function
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>No problem. Probably worth mentioning that the reason that I want to store PivotTable items in dictionary objects when they exist as collections already. Among other things, I want to be able to create &#8216;Custom View&#8217; functionality that works for pivottables, so that the user can save their newly filtered pivottable, and at any time easily return to it, filters already in place. </p>
<p>For anyone else reading along who&#8217;s not familiar with custom views, as per <a href="http://www.ozgrid.com/Excel/AutoFilters_2.htm" rel="nofollow">http://www.ozgrid.com/Excel/AutoFilters_2.htm</a> custom views allow you to do this for autofilter collections by uing View&gt;Custom Views and click the Add button (provided you don&#8217;t have any excel 2007/10 tables in your document &#8211; for some reason these conflict with the Custom View functionality, which is a damn stupid move on part of MS) . Give your view a name and make sure you have a tick next to Hidden rows, columns and filter settings. This is a must to retain all the settings. Click OK. You can then call up your filtered list as a Custom View by going to View&gt;Custom Views, clicking on the name of your view and selecting the Show button.</p>
<p>I want to do something similar with pivottables. So what I want to do is save my pivottabel settings somewhere (likely a hidden sheet), so that I can recreate it at the push of a button. I think the jagged array approach is going to be the best way to do this in terms of  flexibility .. I can easily add further dimensions to hold other data regarding pivotfields, such as hidden items, number formats, whatever.</p>
<p>Whereas with the collection/dictionary approach I would require a separate collection/dictionaries for each subsequent type of attribute, as far as I know. Also with collections, I don&#8217;t believe you can retrieve the key, so I won&#8217;t neccessarily know which set of filter items go with which pivot field. Although I could easily get around this by storing the subdictionary (i.e. the one that contains the pivotitems) in say the 2 element Variant Array; with the field name stored in Variant_Array(0) and the dictionary stored in Variant_Array(1).</p>
<p>Note that this is a dictionary stored within a jagged array stored within a dictionary!</p>
<p>Also, in case anyone is interested, here&#8217;s my code to churn out named ranges from pivotfields:</p>
<p><code></p>
<p>Sub Make_Names()<br />
    Dim pt As PivotTable<br />
    Dim pf As PivotField<br />
    Dim wks As Worksheet</p>
<p>    Set wks = ActiveSheet<br />
    Set pt = wks.PivotTables(1)</p>
<p>For Each pf In pt.VisibleFields</p>
<p>With ActiveWorkbook.Names<br />
   .Add Name:=Fix_Name(pf.Name), RefersTo:="=" &amp; pf.DataRange.Address<br />
    End With<br />
Next pf</p>
<p>End Sub</p>
<p>Public Function Fix_Name(sName As String) As String<br />
'   This code was from Craig Hatmaker. Google 'Beyond Excel' for more info<br />
'   Description:Conforms a string so it can be used as a name</p>
<p>'   Parameters: sName       String to be conformed</p>
<p>'   Example:    sColumnName = Fix_Name("1st deposit %")</p>
<p>'     Date   Ini Modification<br />
'   11/02/10 CWH Initial Programming<br />
'   11/20/10 CWH Used "Like" operator</p>
<p>    'If Not DebugMode Then On Error GoTo ErrHandler<br />
    Fix_Name = sName</p>
<p>    Dim i As Integer</p>
<p>   'Substitute special invalid characters w/standard abbreviations<br />
    sName = Replace(sName, "#", "_NUM")<br />
    sName = Replace(sName, "$", "_AMT")<br />
    sName = Replace(sName, "%", "_PCT")<br />
    sName = Replace(sName, "-", ".")<br />
    sName = Replace(sName, ",", "-")<br />
    sName = Replace(sName, " ", "_")</p>
<p>   'Get rid of all other illegal characters<br />
    i = 1<br />
    Do While i &lt;= Len(sName)<br />
        If Not Mid(sName, i, 1) Like &quot;[A-Z,a-z,0-9,.,_,\]&quot; Then _<br />
            sName = Left(sName, i - 1) &amp; Right(sName, Len(sName) - i)<br />
        i = i + 1<br />
    Loop</p>
<p>   &#039;First Character cannot be numeric &amp; result cannot look like cell ref.<br />
    If IsNumeric(Left(sName, 1)) Or sName Like &quot;[A-Z]#&quot; Then _<br />
        sName = &quot;_&quot; &amp; sName</p>
<p>    Fix_Name = sName</p>
<p>ErrHandler:</p>
<p>    If Err.Number  0 Then MsgBox _<br />
        "Fix_Name - Error#" &amp; Err.Number &amp; vbCrLf &amp; _<br />
        Err.Description, vbCritical, "Error", Err.HelpFile, Err.HelpContext<br />
    On Error GoTo 0</p>
<p>End Function<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug Glancy</title>
		<link>http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/comment-page-3/#comment-213318</link>
		<dc:creator>Doug Glancy</dc:creator>
		<pubDate>Thu, 26 Apr 2012 06:50:31 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2310#comment-213318</guid>
		<description>@ Jeff Weir, thanks for posting the code.  I&#039;ll give it a spin.</description>
		<content:encoded><![CDATA[<p>@ Jeff Weir, thanks for posting the code.  I&#8217;ll give it a spin.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Create Pivot Table Named Ranges - yoursumbuddy</title>
		<link>http://peltiertech.com/WordPress/referencing-pivot-table-ranges-in-vba/comment-page-3/#comment-213317</link>
		<dc:creator>Create Pivot Table Named Ranges - yoursumbuddy</dc:creator>
		<pubDate>Thu, 26 Apr 2012 06:47:51 +0000</pubDate>
		<guid isPermaLink="false">http://peltiertech.com/WordPress/?p=2310#comment-213317</guid>
		<description>[...] In terms of identifying PivotFields, DataFields and other pivot table ranges in code, Jon Peltier wrote a superb post in 2009 that&#8217;s still generating [...]</description>
		<content:encoded><![CDATA[<p>[...] In terms of identifying PivotFields, DataFields and other pivot table ranges in code, Jon Peltier wrote a superb post in 2009 that&#8217;s still generating [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

