Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Output on .csv with 90 line limit

I have the following code that I use to save to a csv. The .csv file for
upload has a limit of 90 lines, therefore I would need to have multi files
created with lines 1 to 90 on one file with a 1 on the end of the file name.
Then lines 91 to 181 with a 2 on the end of the file name until all the lines
are on different files. Is that possible?

Sheets("PO upload").Copy

ActiveSheet.SaveAs _
Filename:=strPOnum1 & " " & Format(Now, "mmddyy") & _
".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close savechanges:=False


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Output on .csv with 90 line limit

Aaron,

The macro below will do that - assumes that your output table starts in cell A1 and is contiguous.
It will save the files in the folder where the workbook with the macro is stored. If it starts
elsewhere, change the line

With Range("A1").CurrentRegion

to reflect the address of the upper left cell.

HTH,
Bernie
MS Excel MVP


Sub ExportTo90LineCSV()

Dim fName As String
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim I As Integer
Dim FCount As Integer
Dim strPOnum1 As String

strPOnum1 = "Whatever"

fName = ThisWorkbook.Path & "\" & strPOnum1 & " " & Format(Now, "mmddyy")

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile

With Range("A1").CurrentRegion
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

For I = StartRow To EndRow Step 90
FCount = FCount + 1
Open fName & " " & FCount For Output Access Write As #FNum

For RowNdx = I To I + 89
WholeLine = ""
For ColNdx = StartCol To EndCol
If WholeLine = "" Then
WholeLine = Cells(RowNdx, ColNdx).Text
Else
WholeLine = WholeLine & "," & Cells(RowNdx, ColNdx).Text
End If
Next ColNdx
Print #FNum, WholeLine
Next RowNdx
Close #FNum

Next I

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True

End Sub



"Aaron" wrote in message
...
I have the following code that I use to save to a csv. The .csv file for
upload has a limit of 90 lines, therefore I would need to have multi files
created with lines 1 to 90 on one file with a 1 on the end of the file name.
Then lines 91 to 181 with a 2 on the end of the file name until all the lines
are on different files. Is that possible?

Sheets("PO upload").Copy

ActiveSheet.SaveAs _
Filename:=strPOnum1 & " " & Format(Now, "mmddyy") & _
".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close savechanges:=False




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Output on .csv with 90 line limit

Ooops - forgot the .csv extension for the filename. Change:

Open fName & " " & FCount For Output Access Write As #FNum

to

Open fName & " " & FCount & ".csv" For Output Access Write As #FNum


HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Aaron,

The macro below will do that - assumes that your output table starts in cell A1 and is contiguous.
It will save the files in the folder where the workbook with the macro is stored. If it starts
elsewhere, change the line

With Range("A1").CurrentRegion

to reflect the address of the upper left cell.

HTH,
Bernie
MS Excel MVP


Sub ExportTo90LineCSV()

Dim fName As String
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim I As Integer
Dim FCount As Integer
Dim strPOnum1 As String

strPOnum1 = "Whatever"

fName = ThisWorkbook.Path & "\" & strPOnum1 & " " & Format(Now, "mmddyy")

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile

With Range("A1").CurrentRegion
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

For I = StartRow To EndRow Step 90
FCount = FCount + 1
Open fName & " " & FCount For Output Access Write As #FNum

For RowNdx = I To I + 89
WholeLine = ""
For ColNdx = StartCol To EndCol
If WholeLine = "" Then
WholeLine = Cells(RowNdx, ColNdx).Text
Else
WholeLine = WholeLine & "," & Cells(RowNdx, ColNdx).Text
End If
Next ColNdx
Print #FNum, WholeLine
Next RowNdx
Close #FNum

Next I

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True

End Sub



"Aaron" wrote in message
...
I have the following code that I use to save to a csv. The .csv file for
upload has a limit of 90 lines, therefore I would need to have multi files
created with lines 1 to 90 on one file with a 1 on the end of the file name.
Then lines 91 to 181 with a 2 on the end of the file name until all the lines
are on different files. Is that possible?

Sheets("PO upload").Copy

ActiveSheet.SaveAs _
Filename:=strPOnum1 & " " & Format(Now, "mmddyy") & _
".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close savechanges:=False






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Output on .csv with 90 line limit

Worked like a charm! This will save me loads of time. Thank you so much!

"Bernie Deitrick" wrote:

Ooops - forgot the .csv extension for the filename. Change:

Open fName & " " & FCount For Output Access Write As #FNum

to

Open fName & " " & FCount & ".csv" For Output Access Write As #FNum


HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Aaron,

The macro below will do that - assumes that your output table starts in cell A1 and is contiguous.
It will save the files in the folder where the workbook with the macro is stored. If it starts
elsewhere, change the line

With Range("A1").CurrentRegion

to reflect the address of the upper left cell.

HTH,
Bernie
MS Excel MVP


Sub ExportTo90LineCSV()

Dim fName As String
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer
Dim I As Integer
Dim FCount As Integer
Dim strPOnum1 As String

strPOnum1 = "Whatever"

fName = ThisWorkbook.Path & "\" & strPOnum1 & " " & Format(Now, "mmddyy")

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile

With Range("A1").CurrentRegion
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

For I = StartRow To EndRow Step 90
FCount = FCount + 1
Open fName & " " & FCount For Output Access Write As #FNum

For RowNdx = I To I + 89
WholeLine = ""
For ColNdx = StartCol To EndCol
If WholeLine = "" Then
WholeLine = Cells(RowNdx, ColNdx).Text
Else
WholeLine = WholeLine & "," & Cells(RowNdx, ColNdx).Text
End If
Next ColNdx
Print #FNum, WholeLine
Next RowNdx
Close #FNum

Next I

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True

End Sub



"Aaron" wrote in message
...
I have the following code that I use to save to a csv. The .csv file for
upload has a limit of 90 lines, therefore I would need to have multi files
created with lines 1 to 90 on one file with a 1 on the end of the file name.
Then lines 91 to 181 with a 2 on the end of the file name until all the lines
are on different files. Is that possible?

Sheets("PO upload").Copy

ActiveSheet.SaveAs _
Filename:=strPOnum1 & " " & Format(Now, "mmddyy") & _
".csv", FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close savechanges:=False







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Output on .csv with 90 line limit

You're quite welcome! Thanks for letting me know that you got my code to work.

Bernie
MS Excel MVP


"Aaron" wrote

Worked like a charm! This will save me loads of time. Thank you so much!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
output to the same line in a Text file? Bernard Excel Discussion (Misc queries) 2 November 25th 09 08:12 PM
Subtotal: Totals line output basic Excel Discussion (Misc queries) 0 March 6th 07 09:28 PM
place output of several debug.print statements on the same line [email protected] Excel Programming 1 August 24th 05 08:40 PM
Trying to start a second line ( ie use of enter key) in an output file Susan Hayes Excel Programming 1 February 26th 05 09:20 PM
Any way to get around the 240-character line limit on text output? awp Excel Discussion (Misc queries) 3 December 14th 04 11:59 PM


All times are GMT +1. The time now is 10:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"