Created
November 9, 2012 14:44
-
-
Save wpsmith/4046082 to your computer and use it in GitHub Desktop.
VBA: Split CSV by rows of 25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Sub Split() | |
| Dim rLastCell As Range | |
| Dim rCells As Range | |
| Dim strName As String | |
| Dim lLoop As Long, lCopy As Long | |
| Dim wbNew As Workbook | |
| With ThisWorkbook.Sheets(1) | |
| Set rLastCell = .Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious) | |
| For lLoop = 2 To rLastCell.Row Step 200 | |
| lCopy = lCopy + 1 | |
| Set wbNew = Workbooks.Add | |
| .Cells(1, 1).EntireRow.Copy _ | |
| Destination:=wbNew.Sheets(1).Range("A1") | |
| .Range(.Cells(lLoop, 1), .Cells(lLoop + 199, .Columns.Count)).EntireRow.Copy _ | |
| Destination:=wbNew.Sheets(1).Range("A2") | |
| wbNew.SaveAs Filename:="Inventory_" & Format(lLoop + 199, "0000") & ".csv", FileFormat:=xlCSV, CreateBackup:=False, Local:=True | |
| wbNew.Close SaveChanges:=False | |
| Next lLoop | |
| End With | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment