I have a workbook with multiple worksheets with multiple rows in each worksheet.
I need new workbooks with the same number of worksheets and one row in each worksheet.
ex: if the workbook contain 8 worksheets with 200 rows in each worksheet, the result will be 200 workbooks containing 8 worksheets with 1 row.
result Workbook (200 workbooks)
Sub Method()
Dim i As Long
Dim TotalRows As Long
Application.ScreenUpdating = False
myPath = ActiveWorkbook.Path
If Right(myPath, 1) <> "\" Then myPath = myPath & "\"
'Count the total rows in the source sheet
TotalRows = Range(Range("A2"), Range("A2").End(xlDown)).Rows.Count
For i = 1 To TotalRows
With Sheets("Report1")
.Rows(2 & ":" & .Rows.Count).ClearContents 'Where X is a variable that = the row number
End With
'Copy range to clipboard
Workbooks("Source.xlsx").Worksheets("Source1").Range("A" & i).Copy
'PasteSpecial to paste values, formulas, formats, etc.
Workbooks("Reports.xlsb").Worksheets("Report1").Range("A2" & i).PasteSpecial Paste:=xlPasteValues
Filename = "ADMS_" & "BTS" & ADMS & ".xlsx" 'Name of saved file
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=myPath & Filename, _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
'ActiveWorkbook.Close True
Application.DisplayAlerts = True
Next i
Application.ScreenUpdating = True
End Sub
xlDown
,... it can give unreliable result. Instead ofTotalRows = Range(Range("A2"), Range("A2").End(xlDown)).Rows.Count
I suggestTotalRows = Range("A" & Rows.Count).End(xlUp).Row - 1
. Check out Error in finding last used cell in VBA for more details. – PonderingPanda