OzGrid

How to copy 300 rows at a time from one column with 3K rows and convert to csv file

< Back to Search results

 Category: [Excel]  Demo Available 

How to copy 300 rows at a time from one column with 3K rows and convert to csv file

 

Requirement:

 

The user has a one-column result that have an alphanumeric data with 3k rows. 

 

The user has an application that has a limitation of processing 300 rows only, and that means the user will have 10 workbooks.

 

The user wants to save each workbook as a separate csv file so it can be processed much faster.

 

Can someone help with this?

 

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/1206313-copying-300-rows-at-a-time-from-one-column-with-3k-rows-and-convert-to-csv-file

 

Solution:

 

Code:
Sub MakeCSVs()
Dim a As Variant, n As Long, fi As Integer
Const b = 300, f As String = "C:\temp\OutFile"
  fi = FreeFile
  With ActiveSheet
    a = .Range("F2:F" & CStr(.Cells(.Rows.Count, "F").End(xlUp).Row)).Value2
  End With
  Open f & "1.csv" For Output As fi
  For n = 1 To UBound(a, 1)
    If (n - 1) Mod b = 0 Then
      Close fi
      Open f & CStr(n) & ".csv" For Output As fi
    End If
    Print #fi, a(n, 1)
  Next
  Close fi
End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by JonathanVH.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to create a macro for saving copy as csv with incremental file number

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)