I've got a spreadsheet with 10 pivot tables (each on separate sheets)...below is a macro for updating one pivottable and moving narrative underneath it pending on whether the table expands/contracts...how can i loop it so that the macro does it for each of the 10 pivottables and then stops (instead of having the macro below, but 10 times longer)...As you can tell, I don't much on VB, so ANY help would be very much appreciated. Thanks
Sub LeadsUpdate()
'Determine how much space the pivottable and leadsheet narrative needs
Columns("a:a".Select
Selection.find(What:="audit objectives", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False).Activate
ActiveCell.Select
'This is where the leadsheet narrative starts
Dim var As String
var = ActiveCell.Row
'This is where the leadsheet narrative should be
Dim var2 As String
var2 = Range("d5"
Dim var3 As String
var3 = Range("e5"
'Determine what should be moved first - pivot table or narrative
If var2 > var Then GoTo Option1 Else GoTo Option2:
Option1:
'Move narrative
ActiveCell.Rows("1:100".EntireRow.Select
Selection.Cut
Range(var3).Select
ActiveSheet.Paste
ActiveCell.Select
'Set pivottable category and refresh pivottable data
Dim var4 As String
var4 = Range("c5"
ActiveSheet.PivotTables("PivotTable4".PivotFields("Subject:".CurrentPage = _
var4
ActiveSheet.PivotTables("PivotTable4".RefreshTable
GoTo Finish:
Option2:
'Set pivottable category and refresh pivottable data
Dim var5 As String
var5 = Range("c5"
ActiveSheet.PivotTables("PivotTable4".PivotFields("Subject:".CurrentPage = _
var5
ActiveSheet.PivotTables("PivotTable4".RefreshTable
'Move narrative
ActiveCell.Rows("1:100".EntireRow.Select
Selection.Cut
Range(var3).Select
ActiveSheet.Paste
ActiveCell.Select
Finish:
Range("a1".Select
End Sub
Sub LeadsUpdate()
'Determine how much space the pivottable and leadsheet narrative needs
Columns("a:a".Select
Selection.find(What:="audit objectives", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False).Activate
ActiveCell.Select
'This is where the leadsheet narrative starts
Dim var As String
var = ActiveCell.Row
'This is where the leadsheet narrative should be
Dim var2 As String
var2 = Range("d5"
Dim var3 As String
var3 = Range("e5"
'Determine what should be moved first - pivot table or narrative
If var2 > var Then GoTo Option1 Else GoTo Option2:
Option1:
'Move narrative
ActiveCell.Rows("1:100".EntireRow.Select
Selection.Cut
Range(var3).Select
ActiveSheet.Paste
ActiveCell.Select
'Set pivottable category and refresh pivottable data
Dim var4 As String
var4 = Range("c5"
ActiveSheet.PivotTables("PivotTable4".PivotFields("Subject:".CurrentPage = _
var4
ActiveSheet.PivotTables("PivotTable4".RefreshTable
GoTo Finish:
Option2:
'Set pivottable category and refresh pivottable data
Dim var5 As String
var5 = Range("c5"
ActiveSheet.PivotTables("PivotTable4".PivotFields("Subject:".CurrentPage = _
var5
ActiveSheet.PivotTables("PivotTable4".RefreshTable
'Move narrative
ActiveCell.Rows("1:100".EntireRow.Select
Selection.Cut
Range(var3).Select
ActiveSheet.Paste
ActiveCell.Select
Finish:
Range("a1".Select
End Sub