This program is supposed to take the value in two combo boxes and use them to populate pivot charts that are in other spreadsheets. So a user would select PS and AMI on sheet one (s) and it would change the pivot table on s1-s9 to look up those chosen fields. I keep getting a subscript out of range error, and I'm not sure if my pivottable.pivotlayout method is correct, but when I recorded a macro (in the very bottom) using activesheet, it worked. How can I fix this?
The error occurs at the first large text, the second large text is the recorded macro.
![]()
Private Sub ChooseButton_Click() Dim s As String Dim ws As Worksheet Dim s1 As String Dim ws1 As Worksheet Dim s2 As String Dim ws2 As Worksheet Dim s3 As String Dim ws3 As Worksheet Dim s4 As String Dim ws4 As Worksheet Dim s5 As String Dim ws5 As Worksheet Dim s6 As String Dim ws6 As Worksheet Dim s7 As String Dim ws7 As Worksheet Dim s8 As String Dim ws8 As Worksheet Dim s9 As String Dim ws9 As Worksheet s = ".csv]Oppty Created to R1 Date L" s1 = "Opportunity Created" s2 = "Submit to ComOps" s3 = "Bid Due" s4 = "Expected Order" s5 = "R1" s6 = "Proposal Promise" s7 = "R2" s8 = "Proposal Submit" s9 = "R3" Set ws = Workbooks("Leading Indicators FW33.xls").Worksheets(s) Set ws1 = Workbooks("Leading Indicators FW33.xls").Worksheets(s1) 'Set ws2 = Workbooks("Leading Indicators FW33.xls").Worksheets(s2) 'Set ws3 = Workbooks("Leading Indicators FW33.xls").Worksheets(s3) 'Set ws4 = Workbooks("Leading Indicators FW33.xls").Worksheets(s4) 'Set ws5 = Workbooks("Leading Indicators FW33.xls").Worksheets(s5) 'Set ws6 = Workbooks("Leading Indicators FW33.xls").Worksheets(s6) 'Set ws7 = Workbooks("Leading Indicators FW33.xls").Worksheets(s7) 'Set ws8 = Workbooks("Leading Indicators FW33.xls").Worksheets(s8) 'Set ws9 = Workbooks("Leading Indicators FW33.xls").Worksheets(s9) ws1.PivotTables("pivottable10").PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 ws1.PivotTables("pivottable10").PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 'ws2.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws2.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 _ ws3.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws3.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 _ ws4.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws4.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 _ ws5.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws5.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 _ ws6.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws6.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 _ ws7.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws7.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 _ ws8.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws8.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 _ ws9.PivotLayout.PivotFields("P&L").CurrentPage = ComboBox2 _ ws9.PivotLayout.PivotFields("Sub P&L").CurrentPage = ComboBox1 'ActiveChart.PivotLayout.PivotFields("Sub P&L").CurrentPage = "(All)" _ Sheets("Sumbit to ComOps").Select _ ActiveChart.PivotLayout.PivotFields("P&L").CurrentPage = "PS" _ ActiveChart.PivotLayout.PivotFields("Sub P&L").CurrentPage = "AMI" _ ActiveChart.PivotLayout.PivotFields("Sub P&L").CurrentPage = "(All)" _ Sheets("Bid Due").Select 'End Sub End Sub
Bookmarks