Hi sebas123
Using your code structure, one way to give you an idea?
Option Explicit
Option Base 1
Sub exporttxt2()
Dim firstrow As Integer
Dim rownum As Integer
Dim colnum As Integer
Dim cnt As Integer
Dim colarr
Dim filename As String
Dim Filelocation As String
Dim ws As Worksheet
Set ws = Worksheets("form")
'Put columns to be output here
'In this case columns B, D, F and K
colarr = Array(2, 4, 6, 11)
Filelocation = "c:\"
With ws
rownum = 3
While .Cells(rownum, 1) <> ""
filename = .Cells(rownum, 1).Value
Open (Filelocation & filename & ".txt") For Output As #1
For cnt = 1 To UBound(colarr)
'Debug.Print filename, ws.Cells(rownum, colarr(cnt)) & vbNewLine
Print #1, ws.Cells(rownum, colnum) & vbNewLine;
Next cnt
Close #1
rownum = rownum + 1
Wend
End With
End Sub
I have only tested this with Debug.Print and not to file(s).
Barry
Bookmarks