Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Select a PivotField range without using the range object

I am trying to update the grouping of some dates in a pivottable using VBA.
Right now I select the pivotfield by using the range object
(Activesheet.Range("B9").select). I would like to do this same process but
by using the PivotField object instead (in case the location of the pivot
field changes, user inserts/deletes rows, etc, etc). My code is below:

For Each pf In pt.PivotFields 'look for TX_Date
If pf.Name = "TX_Date" Then 'found it
pf.Orientation = xlRowField 'move to to the row field
'select tx_date *****CHANGE THIS SO IT ISN'T STATIC*****
ActiveSheet.Range("B9").Select
Set rng = Selection 'slap it in my range variable
'group it
rng.Group Start:=vntSt, End:=vntFin, periods:=Array(False, False,
False, False, True, False, False)
pf.Orientation = xlPageField 'move it back to the page field
For Each pi In pf.PivotItems 'go thru all the values in TX_Date
If InStr(pi.Name, "<") < 0 Or InStr(pi.Name, "") < 0 Then
pi.Visible = False 'if its less than or greater than, don't
show it
End If
Next pi
Exit For 'only 1 TX_Date in pivot, we're done
End If
Next pf
Set rng = Nothing


Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Select a PivotField range without using the range object

Never mind - answered my own question. For anyone who cares to know how I
got around the issue --- in the code below, just replace
"ActiveSheet.Range("B9").Select" with the following:

'go thru entire pivot field data range (includes 2 pivot fields)
For Each cell In pf.DataRange
If cell.PivotCell.PivotField.Name = "TX_Date" Then 'found a value in
TX_Date
cell.Select 'select it
Exit For 'we're done
End If
Next cell

"Mike" wrote:

I am trying to update the grouping of some dates in a pivottable using VBA.
Right now I select the pivotfield by using the range object
(Activesheet.Range("B9").select). I would like to do this same process but
by using the PivotField object instead (in case the location of the pivot
field changes, user inserts/deletes rows, etc, etc). My code is below:

For Each pf In pt.PivotFields 'look for TX_Date
If pf.Name = "TX_Date" Then 'found it
pf.Orientation = xlRowField 'move to to the row field
'select tx_date *****CHANGE THIS SO IT ISN'T STATIC*****
ActiveSheet.Range("B9").Select
Set rng = Selection 'slap it in my range variable
'group it
rng.Group Start:=vntSt, End:=vntFin, periods:=Array(False, False,
False, False, True, False, False)
pf.Orientation = xlPageField 'move it back to the page field
For Each pi In pf.PivotItems 'go thru all the values in TX_Date
If InStr(pi.Name, "<") < 0 Or InStr(pi.Name, "") < 0 Then
pi.Visible = False 'if its less than or greater than, don't
show it
End If
Next pi
Exit For 'only 1 TX_Date in pivot, we're done
End If
Next pf
Set rng = Nothing


Thanks!

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
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Possible to select a range of cells from a Shape Object Gummy Excel Programming 1 May 11th 06 12:06 AM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
how to select two separate ranges into range object Serge[_2_] Excel Programming 2 October 1st 03 03:10 PM


All times are GMT +1. The time now is 06:51 PM.

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

About Us

"It's about Microsoft Excel"