ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Seeting up repetitive code (https://www.excelbanter.com/excel-programming/375539-seeting-up-repetitive-code.html)

Matt

Seeting up repetitive code
 
I want to repeat this code:

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Month").CurrentPage =

in multiple macros...how would I do it? This is my thought thus far but I'm
not sure about the syntax:

Dim repeat As String

repeat =
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Month").CurrentPage = _


If Range("T6").Value = "2"
repeat&"January_2006"
end if

If Range("T6").Value = "3"
repeat&"February_2006"
end if


etc. etc. - any suggestions?

Charles Chickering

Seeting up repetitive code
 
Maybe something like this?
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("Month")
Select Case Range("T6")
Case 2
.CurrentPage = "January"
Case 3
.CurrentPage = "February"
Case Else
.CurrentPage = "Whatever"
End Select
End With
--
Charles Chickering

"A good example is twice the value of good advice."


"Matt" wrote:

I want to repeat this code:

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Month").CurrentPage =

in multiple macros...how would I do it? This is my thought thus far but I'm
not sure about the syntax:

Dim repeat As String

repeat =
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Month").CurrentPage = _


If Range("T6").Value = "2"
repeat&"January_2006"
end if

If Range("T6").Value = "3"
repeat&"February_2006"
end if


etc. etc. - any suggestions?



All times are GMT +1. The time now is 11:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com