Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
RestlessAde
 
Posts: n/a
Default For Each Loop with Pivot Table

Hi,

In trying to overcome the problems associated with corrupted pivot data (as
described in my post VB corrupting pivot tables), I think I know how to solve
the problem, but lack the vba expertise to code it. I would greatly
appreciate if someone could suggest the correct syntax:

I have a pivot table page field called "SA". Using VBA I would like to step
through each value in the field to compare with a user inputed value. The
value in this instance is a name.

So for example, assuming the user enters the name Alex. I would like to loop
through all the values stored in SA to see if there is match. If there is a
match I would like to set the value of SA to Alex. If there is not a match, I
would like to set the value to (blank).

I assume that a For Each statement would do this, but am struggling with the
syntax.

Thanks for your help.

Ra
  #2   Report Post  
Jon Peltier
 
Posts: n/a
Default

I've done this using similar code to what's below (sorry, it's too late
to go looking up the specifics).

Dim piItem as PivotItem
Dim pfField as PivotField

Set ptField = ActiveSheet.PivotTables(1).PivotFields("SA")

For Each piItem in pfField.PivotItems
If piItem.Text = "Alex" Then
pfField.Value = "Alex"
Exit For
End If
Next

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


RestlessAde wrote:
Hi,

In trying to overcome the problems associated with corrupted pivot data (as
described in my post VB corrupting pivot tables), I think I know how to solve
the problem, but lack the vba expertise to code it. I would greatly
appreciate if someone could suggest the correct syntax:

I have a pivot table page field called "SA". Using VBA I would like to step
through each value in the field to compare with a user inputed value. The
value in this instance is a name.

So for example, assuming the user enters the name Alex. I would like to loop
through all the values stored in SA to see if there is match. If there is a
match I would like to set the value of SA to Alex. If there is not a match, I
would like to set the value to (blank).

I assume that a For Each statement would do this, but am struggling with the
syntax.

Thanks for your help.

Ra

  #3   Report Post  
RestlessAde
 
Posts: n/a
Default

Thanks Jon. I implemented a work around in the end, but I'll try this also.

"Jon Peltier" wrote:

I've done this using similar code to what's below (sorry, it's too late
to go looking up the specifics).

Dim piItem as PivotItem
Dim pfField as PivotField

Set ptField = ActiveSheet.PivotTables(1).PivotFields("SA")

For Each piItem in pfField.PivotItems
If piItem.Text = "Alex" Then
pfField.Value = "Alex"
Exit For
End If
Next

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


RestlessAde wrote:
Hi,

In trying to overcome the problems associated with corrupted pivot data (as
described in my post VB corrupting pivot tables), I think I know how to solve
the problem, but lack the vba expertise to code it. I would greatly
appreciate if someone could suggest the correct syntax:

I have a pivot table page field called "SA". Using VBA I would like to step
through each value in the field to compare with a user inputed value. The
value in this instance is a name.

So for example, assuming the user enters the name Alex. I would like to loop
through all the values stored in SA to see if there is match. If there is a
match I would like to set the value of SA to Alex. If there is not a match, I
would like to set the value to (blank).

I assume that a For Each statement would do this, but am struggling with the
syntax.

Thanks for your help.

Ra


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
updating pivot table to include additional rows Ellen Excel Discussion (Misc queries) 8 July 15th 08 01:33 PM
Change Data In Pivot Table John Calder New Users to Excel 1 July 7th 05 10:41 PM
Pivot Table - Multiple consolidation Range tengreen Excel Worksheet Functions 1 July 1st 05 07:18 PM
Pivot table, dynamic data formula Excel GuRu Excel Discussion (Misc queries) 3 May 3rd 05 10:45 PM
Pivot Table Problems Rachel Gonsior Excel Discussion (Misc queries) 3 March 21st 05 07:24 PM


All times are GMT +1. The time now is 05:58 AM.

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"