M
Mike
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!
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!