LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Used Range and Source data of a Pivot Table

First, the .usedrange of a worksheet may not be what you expect. If you've
pivot'ed the table, excel could be showing a larger .usedrange than you would
expect.

But if you can reset the .usedrange, you may find that something like this
works:

Option Explicit
Sub testme()

Dim DummyRng As Range
Dim wks As Worksheet
Dim PTRng As Range

Set wks = Worksheets("sheet5")

With wks
If .PivotTables.Count < 1 Then
MsgBox "Not exactly one pt on this sheet"
Exit Sub
End If

'try to reset the used range
Set DummyRng = .UsedRange

Set PTRng = .PivotTables(1).TableRange2
End With

If DummyRng.Address = PTRng.Address Then
MsgBox "it looks like just a pt"
Else
MsgBox "It doesn't look like just a pt"
End If

End Sub

Sometimes, it's as simple as doing that "set dummyrng = .usedrange". Sometimes,
that doesn't work.

Visit Debra Dalgleish's site:
http://contextures.com/xlfaqApp.html#Unused

For other ways to try to reset that used range.





jh wrote:

I am trying to write a function to ascertain if a worksheet solely
contains a pivot table based on information from elsewhere in that
workbook, E.g. a worksheet containing data formula would return False,
A worksheet containg data and a pivot would return false, a worksheet
containing a pivot of external data would return false, but a
worksheet containing a pivot of data within the workbook would return
true. I'm not sure of any direct way to do this, but am thinking on
the lines if the used range of the sheet matched the range used by the
pivot and the source data did not reference another file that would
give me the correct result, however I can't find any properties for a
PivotTable object. I get as far as wks.PivotTables(1). then help
runs out of help! Could anyone point me in the right direction please?
Thanks J. (Win7/Excel 2007)


--

Dave Peterson
 
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
Excel 2007 Pivot Table Changes the Source Data Range Marilyn Excel Discussion (Misc queries) 0 September 14th 09 07:44 PM
How do I change source data range for an existing Pivot Table? Paolo Sardi Excel Programming 0 January 29th 09 11:02 PM
Code that will rerun or refresh a pivot table (after new data ispasted into the original Pivot Table's Source Range) Mike C[_5_] Excel Programming 3 February 15th 08 06:22 AM
Unfixing source data range for a pivot table using vba freespirited_74 Excel Programming 2 August 22nd 07 08:12 AM
Change the range of a pivot table data source Tony White[_2_] Excel Programming 3 July 11th 05 07:46 PM


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