Hello,
At the moment I have a project where I need to export columns in an Excel file into a text file. This is almost finished. The code I have now saves each row into a separate text file.
The only thing left to do is to select which columns are exported. Not every column is needed in the text file. It needs to become something like: Column 1,3,5 need to be exported. This is where i need some help.
Can annyone give me some pointers?
Here is my code so far:
Sub exporttxt()
Dim firstrow As Integer
Dim rownum As Integer
Dim colnum As Integer
Dim filename As String
Dim Filelocation As String
Dim ws As Worksheet
Set ws = Worksheets("form")
Filelocation = "c:\"
With ws
rownum = 3
While .Cells(rownum, 1) <> ""
filename = .Cells(rownum, 1).Value
Open (Filelocation & filename & ".txt") For Output As #1
colnum = 2
While .Cells(rownum, colnum) <> 0
Print #1, ws.Cells(rownum, colnum) & vbNewLine;
colnum = colnum + 1
Wend
Close #1
rownum = rownum + 1
Wend
End With
End Sub
Thanks,
Sebas123
Bookmarks