Hi,
First time posting on this website! Very next to vb and having spent a good few days searching the net for an answer but to no avail. I'm am hoping that someone maybe able to assist with the following query:
I have a pivot table that has two columns and 29 rows. The essential function that i'd like the VBA code to perform is to open each row to a new worksheet and the for each (29) worksheets to be copied and transferred into new workbooks (the workbooks would then be saved a name contained in the cell). I have been able to write a code that performs this function but i cannot get the code to repeat the action for each cell. The code is attached below:
Sub Macro1()
'
' Macro1 Macro
Dim Cell As Range
Dim b As Integer
Dim a As String
Dim d As String
Dim ws As Worksheet
Range("B4").Select
Selection.ShowDetail = True
ActiveSheet.Name = Range("D2").Text
Cells.Select
Selection.Copy
ActiveSheet.Name = Range("D2").Text
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Name = Range("D2").Text
Cells.Select
Cells.EntireColumn.AutoFit
ActiveWindow.Zoom = 85
Selection.RowHeight = 14.25
Cells.EntireColumn.AutoFit
Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Sheet3").Select
ActiveWindow.SelectedSheets.Delete
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Columns("F:F").Select
Selection.Delete Shift:=xlToLeft
ActiveWorkbook.SaveAs Filename:="J:\" & Range("D2")
ActiveWorkbook.Close
End Sub
Many thanks for any help.
Dan.


Reply With Quote
But it did give me the idea to go back to basics. So i cut all the coding back and I'm just attempting to open an new work book for each cell in the pivot and work my way through the list. The following code works and opens range (B4) then returns to the pivot and opens (B5) in a new worksheet but I don't seem to be able to loop it. The coding has been done via recording of a macro.