-
WSLJM
AskWoody LoungerThis one is awesome as well! I’ll try this one out too!
Thanks so much!!
Lana -
WSLJM
AskWoody LoungerYou make it look so easy! This is awesome!
Thanks Hans!
Lana -
WSLJM
AskWoody LoungerWe have used Access in the past, however we use msquery to download it into Excel, then we use macros to manipulate the data. Likewise, we have formulas in the database as well. In addition, we don’t have Access on any of our desktops anymore. Do you have any ideas on why the macro to change the range is not working? When we manually “fix” the range in the pivot table everything works fine. Below is the recorded macro for when the database (in 2007) is open and I manually fix the range. It’s wierd that it says C1:C16 as the real range is A1:P1048546???
Sub Macro8()
ActiveSheet.PivotTables(“PivotTable1”).ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
“K:GroupsPayroll2008 GL PayrollPayroll UploadsTesting[Trial Balances-NEW.xlsm]data!C1:C16” _
, Version:=xlPivotTableVersion10)
End SubThanks!
Lana -
WSLJM
AskWoody LoungerAhh.. yes, I tried everything except that! Thanks Hans!
Lana -
WSLJM
AskWoody LoungerThis worked perfect… thanks so much Hans. This code will come in handy for not just this project, but I can think of several others that I can use this for as well.
Thanks again!!!
Lana -
WSLJM
AskWoody LoungerPer Hans suggested… I revised the attachment so it made more sense. Below is what I’m trying to accomplish.
Hans has given me code for the orignal part of this post to work… now I need to get the months in column “K” to change in the pivot table as well. (My current macro is just hard coded for now). For example, the pivot table has OCT08, OCT07, OCT08B, YTD Current Year, YTD Prior Year, and YTD Budget as “visible”. When the month in cell “P2” changes, then I need the new months in column “K” to be visible in the pivot table. Of course the calculated items (YTD Current Year, YTD Last Year, & YTD Budget) will already be visible, but I need to make the old months NOT visible, and the new months visible. So if we changed cell “P2” to FEB09, the months in column “K” change to FEB09, FEB09B & FEB08, so I’d need the OCT08, OCT08B & OCT07 to NOT be visible and the FEB09, FEB09B, & FEB08 to be VISIBLE.
Thanks!!
Lana -
WSLJM
AskWoody LoungerNow that Hans was so kind to provide code for the pivot table calc item change, I have the following code (recorded of course), that changes the current period to the new periods. How would I include in Hans original code, a way to have the new periods (FEB09, FEB08, FEB09B) in the pivot table. As you can see below, I manual unselected the OLD periods of NOV08, NOV07, NOV08B and then selected the new months (FEB). The periods I want to select are in columns 9 of the Periods worksheet.
Thanks so much!!
LanaSub test()
With ActiveSheet.PivotTables(“PivotTable2”).PivotFields(“Period2”)
.PivotItems.Visible = True
.PivotItems(“FEB09”).Visible = False
.PivotItems(“FEB09B”).Visible = False
.PivotItems(“FEB08”).Visible = False
.PivotItems(“NOV08”).Visible = True
.PivotItems(“NOV08B”).Visible = True
.PivotItems(“YTD Current Year”).Visible = False
.PivotItems(“YTD Budget”).Visible = False
.PivotItems(“YTD Prior Year”).Visible = False
End WithEnd Sub
-
WSLJM
AskWoody LoungerI love it… thanks Hans!!
Lana -
WSLJM
AskWoody LoungerThe data is coming from our AS400. The software we use is called MAPICS.
-
WSLJM
AskWoody LoungerI already tried to just type it into the SQL area (see below), but it didn’t work… thought I’d give it a whirl. I also tried using the word AND instead of the & sign, and that didn’t work either. The field called BSNBCD is the Period, so I’m trying to join the BSNBCD field with the letter B (as seen in the SQL below… which didn’t work).
SELECT left(BSJ6CD,2), YABSREP.BSJ6CD, YABSREP.BSBPCD, YABSREP.BSJ7CD, YABSREP.BSBQCD, YABSREP.BSBEVA, YABSREP.BSNBCD, YABSREP.BSGRCD, YABSREP.BSJ9CD, YABSREP.BSGPCD, YABSREP.BSGQCD, YABSREP.BSOMCD, LEFT(BSJCNB,4), YABSREP.BSBEVA, BSNBCD & ‘B’
FROM SCAR.AMFLIB.YABSREP YABSREP
WHERE (YABSREP.BSJCNB Between 200700 And 200912) -
WSLJM
AskWoody LoungerThanks Hans… I’m still having trouble with the formula’s. It always gives me these messages:
Error for when I try using the > sign is this one….
SQL0104 – Token > was not valid. Valid tokens: ),.Error for when I try using the & sign is this one…
SQL0104 – Token & was not valid. Valid tokens: +- AS .Now if I just enter ‘B’ in the field, then the letter B shows up down the whole column, but I’m trying to JOIN the period and the letter B. The If statement you gave me gives the 1st error message above.
Any other ideas??
Thanks!
Lana -
WSLJM
AskWoody LoungerYour macro appears to have been recorded for a different pivot table – there is no pivot field named Period and no calculated item named YTD-Curr Yr.
Also, cell F2 contains a mysterious entry OPN that doesn’t occur anywhere in the data so it’ll cause errors.
Without that item, you could use this:
Code:Sub ChangePTPeriodsNEW() Dim strFormula1 As String Dim strFormula2 As String Dim r As Long r = 2 Do While Not Worksheets("Periods").Cells(r, 10) = "" strFormula1 = strFormula1 & "+" & Worksheets("Periods").Cells(r, 10) strFormula2 = strFormula2 & "+" & Worksheets("Periods").Cells(r, 12) r = r + 1 Loop If Not strFormula1 = "" Then strFormula1 = "=" & Mid(strFormula1, 2) Worksheets("Pivot Table").PivotTables("PivotTable1").PivotFields("Month") _ .CalculatedItems("YTD-Current Year").StandardFormula = strFormula1 strFormula2 = "=" & Mid(strFormula2, 2) Worksheets("Pivot Table").PivotTables("PivotTable1").PivotFields("Month") _ .CalculatedItems("YTD-Prior Year").StandardFormula = strFormula2 End If End Sub
You are right Hans… I had recorded the macro for my actual data, and not my example data, sorry about confusing everyone! Anyway, I will try out your code… I’m sure it’s WAY BETTER then what I came up with (see below… I finally got it to work). Mine will be quite lengthy once I add every IF THEN possibility, and then add in the looping. I like yours better, but I need to study it so I understand it first. You are a master at this, and I’m still somewhat of a beginner, at least compared to you. Thanks for the code/help Hans!!
LanaSub ChangePTPeriods()
If Sheet7.Range(“E2”) = 12 Then
Sheet4.Select
ActiveSheet.PivotTables(“PivotTable1”).PivotFields(“Period”).CalculatedItems( _
“YTD-Curr Yr”).StandardFormula = “=” & Sheet7.Range(“J2″) & ” +” & Sheet7.Range(“J3″) & ” +” _
& Sheet7.Range(“J4″) & ” +” & Sheet7.Range(“J5″) & ” +” & Sheet7.Range(“J6″) & ” +” _
& Sheet7.Range(“J7″) & ” +” & Sheet7.Range(“J8″) & ” +” & Sheet7.Range(“J9″) & ” +” _
& Sheet7.Range(“J10″) & ” +” & Sheet7.Range(“J11″) & ” +” & Sheet7.Range(“J12″) & ” +” _
& Sheet7.Range(“J13”)ElseIf Sheet7.Range(“E2”) = 11 Then
Sheet4.Select
ActiveSheet.PivotTables(“PivotTable1”).PivotFields(“Period”).CalculatedItems( _
“YTD-Curr Yr”).StandardFormula = “=” & Sheet7.Range(“J2″) & ” +” & Sheet7.Range(“J3″) & ” +” _
& Sheet7.Range(“J4″) & ” +” & Sheet7.Range(“J5″) & ” +” & Sheet7.Range(“J6″) & ” +” _
& Sheet7.Range(“J7″) & ” +” & Sheet7.Range(“J8″) & ” +” & Sheet7.Range(“J9″) & ” +” _
& Sheet7.Range(“J10″) & ” +” & Sheet7.Range(“J11″) & ” +” & Sheet7.Range(“J12”)ElseIf Sheet7.Range(“E2”) = 10 Then
Sheet4.Select
ActiveSheet.PivotTables(“PivotTable1”).PivotFields(“Period”).CalculatedItems( _
“YTD-Curr Yr”).StandardFormula = “=” & Sheet7.Range(“J2″) & ” +” & Sheet7.Range(“J3″) & ” +” _
& Sheet7.Range(“J4″) & ” +” & Sheet7.Range(“J5″) & ” +” & Sheet7.Range(“J6″) & ” +” _
& Sheet7.Range(“J7″) & ” +” & Sheet7.Range(“J8″) & ” +” & Sheet7.Range(“J9″) & ” +” _
& Sheet7.Range(“J10″) & ” +” & Sheet7.Range(“J11”)Else
Sheet4.Range(“A1”).Select
End If
-
WSLJM
AskWoody LoungerWorks perfect!
Thanks Hans!
Lana -
WSLJM
AskWoody LoungerI like it…thanks!
Lana -
WSLJM
AskWoody LoungerNever mind… I just figured it out… for those interested, here is my formula.
=LEFT(L751,(LEN(L751)-1))Thanks!!
Lana
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Documents, Pictures, Desktop on OneDrive in Windows 11
by
ThePhoenix
1 hour, 1 minute ago -
End of 10
by
Alex5723
3 hours, 41 minutes ago -
End Of 10 : Move to Linux
by
Alex5723
4 hours, 10 minutes ago -
Single account cannot access printer’s automatic duplex functionality
by
Bruce
39 minutes ago -
test post
by
gtd12345
9 hours, 42 minutes ago -
Privacy and the Real ID
by
Susan Bradley
1 hour, 30 minutes ago -
MS-DEFCON 2: Deferring that upgrade
by
Susan Bradley
38 minutes ago -
Cant log on to oldergeeks.Com
by
WSJonharnew
14 hours, 3 minutes ago -
Upgrading from Win 10
by
WSjcgc50
1 hour, 27 minutes ago -
USB webcam / microphone missing after KB5050009 update
by
WSlloydkuhnle
9 hours, 9 minutes ago -
TeleMessage, a modified Signal clone used by US government has been hacked
by
Alex5723
1 day, 5 hours ago -
The story of Windows Longhorn
by
Cybertooth
17 hours, 27 minutes ago -
Red x next to folder on OneDrive iPadOS
by
dmt_3904
1 day, 7 hours ago -
Are manuals extinct?
by
Susan Bradley
3 hours, 56 minutes ago -
Canonical ditching Sudo for Rust Sudo -rs starting with Ubuntu
by
Alex5723
1 day, 16 hours ago -
Network Issue
by
Casey H
1 day, 3 hours ago -
Fedora Linux is now an official WSL distro
by
Alex5723
2 days, 4 hours ago -
May 2025 Office non-Security updates
by
PKCano
2 days, 5 hours ago -
Windows 10 filehistory including onedrive folder
by
Steve Bondy
2 days, 7 hours ago -
pages print on restart (Win 11 23H2)
by
cyraxote
1 day, 8 hours ago -
Windows 11 Insider Preview build 26200.5581 released to DEV
by
joep517
2 days, 9 hours ago -
Windows 11 Insider Preview build 26120.3950 (24H2) released to BETA
by
joep517
2 days, 9 hours ago -
Proton to drop prices after ruling against “Apple tax”
by
Cybertooth
2 days, 16 hours ago -
24H2 Installer – don’t see Option for non destructive install
by
JP
1 day, 9 hours ago -
Asking Again here (New User and Fast change only backups)
by
thymej
3 days, 4 hours ago -
How much I spent on the Mac mini
by
Will Fastie
11 hours, 30 minutes ago -
How to get rid of Copilot in Microsoft 365
by
Lance Whitney
1 day, 7 hours ago -
Spring cleanup — 2025
by
Deanna McElveen
3 days, 9 hours ago -
Setting up Windows 11
by
Susan Bradley
2 days, 5 hours ago -
VLC Introduces Cutting-Edge AI Subtitling and Translation Capabilities
by
Alex5723
3 days, 5 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.