473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Macro for PivotTable Field List Options

8
Dear Reader

My excel workbook consists of the following:-

Sheet1: Data for pivot table
Sheet2: Pivot Table
Sheet3: Options to be checked in the "Values" of the PivotTable Field List.

Is there a macro for automatically checking options in the pivottable field list from the values in Sheet3?


Thanks in advance. :)
Mar 29 '13 #1

✓ answered by Rabbit

Compare line 11 in your second block of code with lines 9 and 10 in your first block of codes.

Also, you have an infinite loop. I don't understand the loop you initiate on line 6. You never change its value so the loop is never going to exit.

Finally, I would avoid using the code to activate sheets. Just reference the sheets explicitly.

7 4599
Rabbit
12,516 Expert Mod 8TB
Your question has been moved to the Access VBA forum as that's closer to the topic of the thread.

Yes there is. If you record a macro of you checking the option for the pivot table, you can then go in and edit the literal reference to your cell reference.
Mar 29 '13 #2
sg123
8
Dear Rabbit

Thank you for your post. I was able to record the following code:-

Expand|Select|Wrap|Line Numbers
  1.  Dim UserName As String
  2. Sheets("Sheet3").Activate
  3.  Range("A2").Select
  4.  
  5.  Do Until (ActiveCell.Value = "")
  6.  UserName = ActiveCell.Value
  7.  
  8. ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables("PivotTable1").PivotFields(UserName), "Count of " & UserName, xlCount
  9.     With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of " & UserName).Caption = "Sum of " & UserName
  10.     .Function = xlSum
  11. End With
  12. Loop
  13. End Sub
But, I am getting run-time error '1004' : Unable to get the PivotTables property of the Working Class. Any ideas?
Mar 29 '13 #3
Rabbit
12,516 Expert Mod 8TB
Your active sheet is sheet3. I thought you said your pivot table was on sheet2? You would need to use sheet2, not your active sheet.
Mar 29 '13 #4
sg123
8
Now I am getting the error 'Invalid Qualifier' for the 'Sum of & UserName' in the 4th last line in the code which reads as follows:-

Expand|Select|Wrap|Line Numbers
  1. Dim UserName As String
  2.  
  3.  Sheets("Sheet3").Activate
  4.  Range("A2").Select
  5.  
  6.  Do Until (ActiveCell.Value = "")
  7.  UserName = ActiveCell.Value
  8.   Sheets("Sheet2").Activate
  9.  
  10.     ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables("PivotTable1").PivotFields(UserName), "Count of " & UserName, xlCount
  11.     With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of " & UserName).Caption = "Sum of" & UserName.Function = xlSum
  12.     End With
  13. Loop
  14. End Sub
  15.  
Mar 29 '13 #5
Rabbit
12,516 Expert Mod 8TB
Compare line 11 in your second block of code with lines 9 and 10 in your first block of codes.

Also, you have an infinite loop. I don't understand the loop you initiate on line 6. You never change its value so the loop is never going to exit.

Finally, I would avoid using the code to activate sheets. Just reference the sheets explicitly.
Mar 29 '13 #6
sg123
8
Thank you for your help. My problem is solved. :)
Apr 5 '13 #7
Rabbit
12,516 Expert Mod 8TB
Glad you got it working.

I moved the thread again because we just opened up a new Excel forum.
Apr 5 '13 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Ward B | last post by:
Greetings all. I'm getting the following error message... Unknown column 'icaodesc' in 'field list' when I try to update a table from a PHP form. What 'field list' is it referring to? My...
0
by: Filo | last post by:
Hello, Design nice PivotTable or PivotChart (selecting fileds,captions, colors, fonts, order of fieds etc.) sometimes takes more then 1 hour and I hate when after this my boss (or I self) ask me...
2
by: Nospam | last post by:
I installed a script that is suppose to accept paypal, however on trying to test a payment, I get this error msg: Error Database access error and I get this error msg emailed to me:
1
by: wcamp | last post by:
I would like a "field list" to appear in report design. Clicking the "filed list" icon nothing happens. Have tried dozens of ways to get a "field list", so far no luck! Have created over 5 ACCESS...
2
by: gerryblanco | last post by:
Hi, After creating all my tables, forms, and queries... I entered some sample data for testing... all was working... at the last minute I decided to add a text field in one of my tables. When I...
7
chunk1978
by: chunk1978 | last post by:
hello. so i have 2 select menus which add and remove options from a 3rd select menu... it seems, however, that it's not possible to use different select menus to toggle a 3rd, because when an...
3
G Jones
by: G Jones | last post by:
Let me start by saying I am a graphic designer who understand things very well, but by no means am I a programmer or developer. So here is my question.... I have put together a simple form that...
1
by: ebernedo | last post by:
Hey guys, I have two main questions First off (pictures are kind of blurry) I have this table http://i197.photobucket.com/albums/aa109/ebernedo/DiscTable.jpg And thats my database I use my...
4
by: tofusunday | last post by:
I am pretty new to editing things in vba access. I have a report that didn't have a field that I needed in the field list, I modified the recordsource query, it is a sql pass through query: SELECT...
3
by: kevinkwh | last post by:
Hi, I'm an intern student and my boss told me to do porting from Linux c to Visual C++.When I built the coding, I found this error "unexpected in macro formal parameter list", here is the coding...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.