Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA Pivot Table: Determining item from one field based on anotherfield item

Hi all,

I have a Table/Listobject with a task list. I'm summarizing and performing calculations using a Pivot table. I want to use the Pivot as an interface to the user so that I can manipulate the task list data (datasource) through code.

For example, if the user selects a task on the pivot table, and clicks a button, the associated code would get the task name from the pivot table, and determine via code the task ID, so that it would be possible to change any task data in the table (status, due date, etc). Unfortunately, I haven't figured out how to grab the task ID from the task name.

Here a sample code, I have tried out:

-------Code start---------
Dim r As Range
Dim pvt As PivotTable

On Error GoTo errpart

Set r = ActiveCell
Set pvt = Worksheets("Task by Project").PivotTables("pivot_tasks")

Idx = 0
If r.PivotField.Name < "Task" Then
MsgBox "Selection is not a task.", vbCritical, "Error"
Else
For i = 1 To pvt.PivotFields("Task").PivotItems.Count
s = pvt.PivotFields("Task").PivotItems(i).Name
If s = r.PivotItem.Name Then Idx = i
Next i
If Idx 0 Then
MsgBox pvt.PivotFields("UID").PivotItems(Idx).Name
End If

End If

Exit Sub
errpart:
MsgBox "Selection is not inside table.", vbCritical, "Error"
-----Code Finish----

With the code above, the ids I'm getting doesn't match the data in the datasource, which leads to the conclusion that the indexes from one Pivotitems collection from one pivotfield are not "synchronized" to the Pivotitems collection from another pivotfield.

Please, any help is very appreciated.

Regards,
Alex
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
Need Help Using Calculated Field or Item in Pivot Table sg[_2_] Excel Worksheet Functions 1 June 28th 07 03:28 PM
Pivot Table Calculated Field / Item tc69 Excel Programming 2 May 11th 07 09:14 PM
Overwrite field item name in a Pivot table Mat N Excel Discussion (Misc queries) 0 October 19th 06 04:21 PM
Pivot Table Calculated field item Tim Excel Discussion (Misc queries) 1 September 24th 05 12:31 AM
Delete item from Pivot Table field? Stephen Charts and Charting in Excel 1 September 23rd 05 04:46 PM


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