Hi- I keep getting the error "for without next" on this code:
The code essentially exports a number of sheets from a workbook along with the raw (hardcoded data and saves. What I'm trying to do is change the pivot source of each pivot within the sheet. I think I'm not too far away from resolving..
Thanks in advance
Sub exportsheets()
Dim wbNew As Workbook
Dim rngtm As Range
Dim strPath As String
Dim rSourceData As Range
Dim LastRow As Long
Dim LastCol As Long
'On Error GoTo Errorcatch
Application.ScreenUpdating = False
strPath = "C:\Users\pandoan\Desktop\test\"
Set rngtm = Sheets("Flow TM's").Range("A1")
Do
Sheets(Array("hardcoded data", rngtm.Value)).Copy
Set wbNew = ActiveWorkbook
With wbNew
.Sheets("hardcoded data").Visible = False
Application.Goto .Sheets(1).Range("B13"), True
Range("F5:G5", "T3:U3").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B2").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
For Each Pivot In Sheet.PivotTable.ChangePivotCachePivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=rSourceData)
With Worksheets("hardcoded data")
LastRow = .Cells(.Rows.Count, "DZ").End(xlUp).Row
Set rSourceData = .Range("DZ1:ER" & LastRow)
End With
wbNew.SaveAs strPath & rngtm & Format(Date, "ddmmmyyyy") & ".xlsm", FileFormat:=52
ActiveWorkbook.Close
Do
Set rngtm = rngtm.Offset(1, 0)
Loop Until IsEmpty(ActiveCell)
Application.ScreenUpdating = True
End Sub
The code essentially exports a number of sheets from a workbook along with the raw (hardcoded data and saves. What I'm trying to do is change the pivot source of each pivot within the sheet. I think I'm not too far away from resolving..
Thanks in advance
Sub exportsheets()
Dim wbNew As Workbook
Dim rngtm As Range
Dim strPath As String
Dim rSourceData As Range
Dim LastRow As Long
Dim LastCol As Long
'On Error GoTo Errorcatch
Application.ScreenUpdating = False
strPath = "C:\Users\pandoan\Desktop\test\"
Set rngtm = Sheets("Flow TM's").Range("A1")
Do
Sheets(Array("hardcoded data", rngtm.Value)).Copy
Set wbNew = ActiveWorkbook
With wbNew
.Sheets("hardcoded data").Visible = False
Application.Goto .Sheets(1).Range("B13"), True
Range("F5:G5", "T3:U3").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B2").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
For Each Pivot In Sheet.PivotTable.ChangePivotCachePivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=rSourceData)
With Worksheets("hardcoded data")
LastRow = .Cells(.Rows.Count, "DZ").End(xlUp).Row
Set rSourceData = .Range("DZ1:ER" & LastRow)
End With
wbNew.SaveAs strPath & rngtm & Format(Date, "ddmmmyyyy") & ".xlsm", FileFormat:=52
ActiveWorkbook.Close
Do
Set rngtm = rngtm.Offset(1, 0)
Loop Until IsEmpty(ActiveCell)
Application.ScreenUpdating = True
End Sub