Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for last column of a comma delimted file

Status
Not open for further replies.

databaser

MIS
Feb 11, 2007
9
0
0
US
My problem is when Excel saves a csv file and the columns on the end are null. The csv file has commas for all the columns for only about 16 rolls. After that it just stops putting the commas in for the null columns. How can I test using VBA to see if I am at the end of the line and no more comma separted fields exist in that row.
 
Maybe something like this:

Code:
Sub SaveAsCommaDelimited()
Dim r as integer, c As Integer
Open "C:\Documents and Settings\sam\Desktop\OutFile.txt" For Output As #1
With ActiveSheet.UsedRange
   For r = 1 To .Rows.Count
      For c = 1 To .Columns.Count - 1
          Print #1, .Cells(r, c); ",";
      Next c
      Print #1, .Cells(r, .Columns.Count)
   Next r
End With
Close #1

End Sub

sam
 
ps this probably go to VBA Visual Basic for Applications forum707
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top