Unable To Get Parent Item Property In Pivot Table Using VBA
May 28, 2014
I'm trying to get the parent item name of a clicked cell (e.g. when I double click on field "Commessa 2" I'd like to get "Region 3" and pass it to another sheet)
Here is my code:
[Code] .....
When I run this code, I get the message "Unable to get the ParentItem property of the PivotItem class"
I have created quite a nice little macro that; drills through a lot of key figures, updates a pivot chart and copies the chart to powerpoint.
However it crashes on one particular data set every time with this error: Run-time error '1004': Unable to set the _Default property of the pivot item class
The code where the debugger stops is the last line below here.
I can manually change the pivot chart to the keyfigure it crashes on and thereby workaround the problem in the macro. Also it works for more than 50 other keyfigures without problems.
I'm not grasping the Pivot Table correctly. I've written code to create a sum of values based on a worksheet. Specifically:LocationIDDeptSum of Hours Worked. Location, ID and Dept are rows. This effectively provides the aggregate values that I need based on the row groupings.Here's where this is falling apart. I need to create a new worksheet based on these values. I assumed the three row values - Location, ID and dept - would be in a hierarchy. It's possible they are, I just can't figure out the object model.
When I loop through the PivotItems collection of the PivotFields("Location"), I get what I need. However, I'm unable to determine how to loop through the child values (just for that location). PivotFields("ID") returns all IDs. I can't figure out how to return only the child entries for each pivot item. GetPivotData hasn't been very useful for this. As far as I can tell, GetPivotData, while its return type is listed as Range, throws an error when more than one cell is returned. Worst case, I suppose I can just parse the data in the DataBodyRange of the pivot table - maybe not, I haven't tried that. I'm hoping there's a way to iterate through these collections, but based on what I've seen from Google searches, there may not be. Does my pivot table need to be rearranged? I suppose I could also just dump this data into a data table
I need to filter a pivot table based on a field property. Sort of strange, but the database I get the PivotTable data from returns the Week in the accounting month. as the field name. It has several properties which I have figured out how to expose including the period end date. Now I need to figure out how to filter the PT based on that.
The following shows the property:
Code: ActiveSheet.PivotTables("PivotTable4").CubeFields("[Time]").AddMemberPropertyField Property:="[Time].[Week in Month].[End Date]
Now if I just knew how to filter with that value I could move on the the next issue ....
I am unable to right click anywhere inside a pivot table in any sheet i... i have to create a new pivot table in a new workbook and I am unable to right click over there too.
I am using Excel 2007 and my version of visual basic is 6.5.
I am baffled by the behavior of this code to manipulate one of my pivot tables. I am trying to set all but one of the pivot items in one of the pivot fields to not visible. Because there is a large number of items, I wish to suspend all automatic updates until all items are properly set to visible or non visible.
------------------------------------------------------ Sub SwitchBoards() Dim BoardNew As String Sheets("Board Parameters").Select ' Make sure we get the right value.
[Code].....
The MsgBox returns with: "Manual update is set to False" right after the instruction to set it to True!!
I have a database of roughly 9000 rows. My first sheet is this data in a raw format (Masterdata!). Each row is a fire-rescue response call and therfore has a time stamp. The raw data uses different formats to provide the time stamp. My second sheet is my filtered data (Filtereddata!). In order to make these time stamps uniform I have a formula that looks at the Masterdata! timestamp column and if it is in a numeric format changes it to a text date and if it is a text date perserves it.
This gives me the "timestamp" which has both the incident start time and the date. I have =left and =right formulas breaking apart the date and the time. Therefore I have two columns on my Filtereddata! for the date of the incident and the time the call came in. What I would like to do is run some pivot tables and group incidents by month. I am unable to group them once I run the pivot table. I get a "Unable to group these items" (or something like this) message. I have assured multiple times that the date column is in DATE format. However, when I change the date to long date or short date I see no changes in the column so I am assuming there is something happening that I'm missing. The formula populating the date column on Filtereddata! is as such:
I'm trying to insert a calculated row in a pivot table. I keep getting the error message 'Pivot table items can only refer to items in the same field as the calculated item'
Below is the format of my data:
Region(All) Sub Division(All) Sub Cluster(All) Cluster(All) A/C Level 3(All) A/C Level 1(All) A/C Level 4(All) A/C Level 5(All) Division(All)
Values A/C Level 2Sum of FY11Sum of FY12Sum of FY13 Net Revenues 100 200 300 Op Exp 50 40 30 Calculated Field50 160 270
Attached is a worksheet example, of my beauty salon with 5 therapists.
The input sheet - is the shhet into which I input data on a daily basis.
Weekly inc - This sheet shows the total that each therapist made in apivot table based on the input. The week numbers are 1 to 52 (or 53) depending on each financial year (07/08, 08/09 etc).
What I want to do is either have another pivot table or to add an calculated item to the weekly inc pivot table showing me how much commission each therapist took each week? This is to be done automatically by excel.
This commission is calcluated by using the target comm figures - E.G. Leanne's target is £480 - so she has to earn £480 a week before getting a commission. So if in a week she earns £500 - she will get a commission on £20 (£500 - £480). The commission is 10%, so she will earn £2 that week.
I want to calculate the difference between Budget and Forecast, in € and %. I was trying to use a calculated Item but whenever I place the cursor on the Budget, Forecast or Category cells and try "Calculated Item", I get an error message saying that the Item cannot be modified..
I have cut down my problem to its simplest form - in the real world my spreadsheet is significantly more complex but the attached spreadsheet demonstrates it nicely!
The data is straightforward. PT1 shows the data without a calculated item whilst PT2 is the same PT but with the addition of a calculated item for GP (i.e Sales - COS). Unfortunately adding this has resulting in the PT growing and adding "ilogical" combinations of data that didn't exist in the source data.
In my current project I have "cheated" by using a helper column and filtering on this using the Worksheet_PivotTableUpdate event to hide the unwanted rows but surely there must be a way of removing them "properly".
Another problem, and I guess this is just the way it is, is that my PT takes ages to calculate presumably becuase it is calculating this formula for every combination of values?
I have an issue with a calculated item in my pivot table, because in the totals and subtotal it shows the sum of the column but I want to show the formula that I've specified to the calculated item.
For example, in the attached file, I have in rows the field "name" that has four values (A,B,C,D), in columns the field "Groups" that has "G1" and "G2". I add in the rows the calculated item "G1/G2" that has the formula G1/G2. The problem is that in the total the column "G1/G2" doesn't show the division of the total of "G1" and "G2".
Layout: Rows: City, Restaurant, Cashflow Column: Date (Month/Year) DataField: $Amount
"City" might be 7 cities "Restaurant" may be 32 restaurants, some in some cities; but not other "CashFlow" can be either "Revenue" or "Expense"
The layout of the Pivot table is nice, only shows the Rows where a State, Restaurant, and CashFlow entry exists for at least one Date on that row. And there are no extraneous rows for combinations that don't exist.
Now.... the trouble...
I added a Calculated Item, "Profit" which = "Revenue" - "Expenses". Now, every possible combination of State and Restaurant appears in the pivot table displayed. Only the "Profit" (calculated item) is shown for the previously hidden rows; and of course it's "$0.00" since there are no "Revenue" or "Expense" entries.
How can I get the Pivot table to not display the results of a Calculated Item row, when there are no entries otherwise for that row combination?
Is there a way to condition the Calculated Item to not calculate if there are no data entries in the addends for a particular combination?
I am having an issue with my macro code. Basically I am trying to filter a pivot table by selected criteria. The code seems to be correctly filtering the pivot table but the table appears with no data in it unless I manually refresh the table. This defeats the purpose of automating with a macro. I have attempted a "work around" of just refreshing the pivot table after the filtering is complete but that was unsuccessful. Here is the macro code:
Sub BigReportMacro()
Dim pt As PivotTable Dim pi As PivotItem Dim pf As PivotField Dim E
Having problems with trying to get my vba code to access the SpecialCells property. Receiving the following error.... Unable to get the SpecialCells property of the Range class. The section of my code is below that is causing the error. Keeps stopping on the "Selection.SpecialCells(xlsCellTypeVisible).Select" line.
Sheets(" Book Query").Range("A6:I6").Select Sheets("Book Query").Range(Selection, Selection.End(xlDown)).Select Selection.SpecialCells(xlsCellTypeVisible).Select Selection.Copy Sheets("Inventories and Variances").Select Sheets("Inventories and Variances").Range("A7").Select
why this won't work or at least a way to accomplish the same thing. Basically, I'm trying to hide unneeded data by making the font the same color as the cell:
I went through a lot of threads in this forum, although there were a couple relating to the same problem am facing, they didnt solve my error .. so here's my question again ..
When am trying to delink charts , i get an error stating "Unable to set the formula property of series class".
The code is as follows :
Sub DelinkChartData()
Dim iCtr As Integer, iChars As Integer, SH As Shape, iPlotOrder As Integer Dim nPts As Long, iPts As Long 'Holds the total no of points in the chart Dim xArray, yArray, sChtName As String, sSrsName As String Dim xVals, yVals Dim ChtSeries As Series ' var used to loop thru the series collection Dim ws As Worksheet Dim sChartType As String, iCtr1 As Integer
I want the data field to change to a different field when a command button (cmd_view) is clicked. So when the command button has a caption of "Toggle to Feeds", the code changes the field from Sqm to Feeds, and changes the caprion on the command button to "Toggle to Sqm". When this is next clicked, the fields are swithed over, and the command button caption changes relative to it.
The code I have written is below:
The problem I have is when the code changes the view from feeds to Sqm, it works fine, but when the code changes from Sqm to feeds, it crashes out in the true part of the If statement on the code line ".orientation = xlhidden" with the error "Unable to set the Orientation property of the PivotField class".
As the code for the change of view is the same, apart from the field names, I am at a loss on what is the cause.
I have tried to record a macro to see if the field names appear differently, but they do not.
Sub Tog_pivot()
Dim Toggle As String Application.ScreenUpdating = False Toggle = Sheet5.cmd_View.Caption
If Toggle = "Toggle to Feeds" Then 'switch view from Sqm to Feeds Range("F12").Select ' hide existing field With ActiveSheet.PivotTables("Pivot_forecast_old").PivotFields("Sum of Sqm") .Orientation = xlHidden End With ' Create & display new field "Feeds"......................
I protect the Sheet1 Review > protect sheet and selected two checkboxes from protect sheet property "Select locked Cell" and "Select unlocked cells".
It is working fine and it does not allow the user to view the locked cells B17:B24 while protection is on.
I have a RadioButton1 on the same Sheet1 and i put the following code behind the button to hide the 4 up to 10 rows. When i will press the button while password protection is on; it is giving me the following error:
Unable to set the Hidden property of the Range class.
I've been using the following code successfully for years. Today I would get the error 1004:Unable to set the visible property of the worksheet class. All my searches came up with someone not realizing they had protected the workbook. As you can see, the first thing I do before trying to set the worksheet visible is to unprotect the workbook. In frustration and on a lark I tried .Sheets("items").Visible = True and it worked. These kind of intermittent errors in Excel VBA are very frustrating. Can anyone tell me what I am doing wrong?
I keep getting that error when I'm running my macro. When I debug, it points me to the bolded line in the code below. The larger macro I'm running this function in runs this function some 101 times without error before this happens.
The values of the parameters are as follows when it gives me the error: Find_Exact("hchen", ws1, "B:B"). The first parameter is the only one that changes in the previously mentioned running of this function.
I am trying to look at column at of two different workBOOKS and then when a match is found take the value from column D in workbook two and copy it to the corresponding row in the current column of workbook one.
this is the code I'm using and I get that unable to get the vlookup function. I thought maybe it was because not all of them will have matches so it could return an error if it is trying to return empty, so I put int on error resume next, and it ran through but never brought over ANY data, and there ARE matches and data to be brought over.
destRng is the range in the current column(that i just inserted) on the active worksheet that we will be putting the new info into. srcRng is the range in column A on the other workbook that the numbers are being compared to. src is just an integer
However am receiving an error: "Unable to set the Weight Property of the Border Class". The odd thing is, I only receive the error on the following 2 lines:
The sheet is not protected, events are disabled, and the range that gets selected changes dynamically based on the number of rows of data in the table, however in this example cells A3:L15 are selected.
I made a macro to plot several line graphs on two axis (up to 5) side by side. I made the macro open up the files i need, and extract the necessary data into a common workbook. I put the common element, time as the x axis and heat as one y axis and pressure as the secondary axis. The source data on the excel worksheet is as follows:
(column A = time; column b = heat1; column c = pressure1, column d= heat2; and so on.
So when i have 3 workbooks i need to compare, it should have 6 lines. 3 sources work fine, but 2 sources gives me the "Unable to set the AxisGroup Property of the series class" error message.
Code: Sub LockByColor() ActiveSheet.Unprotect "pc" Dim cl As Range For Each cl In Range("$BO$1:$BZ$45") If cl.Interior.Color = 6299648 Then cl.Locked = True Else: cl.Locked = False End If Next cl ActiveSheet.Protect "pc" End Sub
I have been working on this small project and I it works to create checkboxes and check what boxes are checked. However, at the end of checking which boxes are checked there is a pop up error message saying Run-Time error '1004': Unable to get the CheckBoxes property of the Worksheet class. These are the lines of code, where is the error?
Sub IsBoxChecked() Dim titles(200) As String Dim wks As Worksheet
However the code stops right on the q3 line where the match function is located. The problem is that I'm getting a Run Time Error 1004:
"Unable to get the match property of the worksheet function class"
This would lead me to believe that the match function is not working. However, in Excel, it does work. Even when using the cell from the other Workbook, it works.
All the dates which appear to be dates are indeed formatted as dates.
The range is good. I've used the immediate window to verify the address and the values of the other variables in play.