aleatoricallysimple
New Member
- Joined
- Mar 29, 2011
- Messages
- 3
Hi all,
i'm new to the forum so sorry if I make any message faux pa's.
I'm doing a bit of a pivot table and I've got a bit stuck in some of the coding and I was hoping someone would be able to hlep me out a bit.
I've written a vba so far that basically uses a checkbox to decide the filters for my pivot. (I wish work had excel 2010 as then I could have just used the slicer function.)
I've got so far the filters on and off, the problem is because there was a bit of a weird date naming convention the order for the months isn't working too well as they are considered text and not months - that or when I try using the filter names in can't find them.
So to get around this fact as its not that practical to change the dates - used a couple of formulas to create a list of the right order of filters in an excel spreadsheet. therefore the range is:
What I want to so is say in the vba:
If A2 contains a number then use the content in cell B2 to define the order of the pivot table.
Code so far:
Can anyone help me out please?
i'm new to the forum so sorry if I make any message faux pa's.
I'm doing a bit of a pivot table and I've got a bit stuck in some of the coding and I was hoping someone would be able to hlep me out a bit.
I've written a vba so far that basically uses a checkbox to decide the filters for my pivot. (I wish work had excel 2010 as then I could have just used the slicer function.)
I've got so far the filters on and off, the problem is because there was a bit of a weird date naming convention the order for the months isn't working too well as they are considered text and not months - that or when I try using the filter names in can't find them.
So to get around this fact as its not that practical to change the dates - used a couple of formulas to create a list of the right order of filters in an excel spreadsheet. therefore the range is:
Code:
Sheet = "Admin"
range B2:B12
contents
B2=sep-10
B3=Oct-10
B4=Nov-10
etc.
If A2 contains a number then use the content in cell B2 to define the order of the pivot table.
Code so far:
Code:
(within sub)
Dim pos1 as string
Dim pos2 as string
Dim pos3 as string
Dim pos4 as string
Dim pos5 as string
pos1 = worksheets("Admin").range(B2)
pos2 = worksheets("Admin").range(B3)
pos3 = worksheets("Admin").range(B4)
pos4 = worksheets("Admin").range(B5)
pos5 = worksheets("Admin").range(B6)
Worksheets("Admin").Activate
If worksheets("Admin").range(A2) = ISnumber? then with ActiveSheet.PivotTables("Data PT").PivotFields("Month").PivotItems(pos1)Position = 1
End With
End If
If worksheets("Admin").range(A3) = ISnumber? then with ActiveSheet.PivotTables("Data PT").PivotFields("Month").PivotItems(pos2)Position = 2
End With
End If
If worksheets("Admin").range(A4) = ISnumber? then with ActiveSheet.PivotTables("Data PT").PivotFields("Month").PivotItems(pos3)Position = 3
End With
End If
'etc for last 2
End Sub
Can anyone help me out please?