Hi All,
I have the following code and it spits out one large CSV - roughly 5.2M rows. Is there a way to code this to spit out multiple CSVs in increments of 1M rows? i.e. with 5.2M rows it should shoot out 6 csv files (5 with 1M rows and 1 with .2M rows)
Code
Sub CreateOutput()
Dim PatternCount As Long
Dim CityCount As Long
Dim PatternList() As Patterns
Dim Prefix As String
Dim Keyword As String
Dim Airport As String
Dim Group As String
Dim OutKeyword As String
Dim I As Long, J As Long
'Initialise.
PatternCount = Sheet2.[A1].CurrentRegion.Rows.Count - 1
CityCount = Sheet1.[A1].CurrentRegion.Rows.Count - 1
Open ThisWorkbook.Path & "\AirOutputSample.csv" For Output Lock Read Write As #1
Write #1, "Ad Group Prefix", "Ad Group", "Keyword", "Airport Code"
'Load data from City - Top Patterns.
ReDim PatternList(PatternCount)
For I = 1 To PatternCount
With Sheet2
PatternList(I).Theme = .Cells(I + 1, 2)
PatternList(I).Keyword = Application.WorksheetFunction.Proper(.Cells(I + 1, 3))
End With
Next I
'Load data from next row in Input - City List.
For I = 1 To CityCount
Application.StatusBar = "City " & I
With Sheet1
Prefix = .Cells(I + 1, 4)
Keyword = .Cells(I + 1, 5)
Airport = .Cells(I + 1, 6)
End With
'Create output.
For J = 1 To PatternCount
Group = Prefix & " - " & PatternList(J).Theme
OutKeyword = Replace(PatternList(J).Keyword, "{city}", Keyword)
Write #1, Prefix, Group, OutKeyword, Airport
Next J
Next I
Application.StatusBar = False
Close #1
End Sub
Display More