Generate .txt file from 2 cols of data

M

mluetkem

What do I need to do to generate a text file from 2 (sometimes not
adjacent) columns of data. Say I have a matrix of date C6:S149.
Column C contains the x data (Time) and columns D thru S contain 16
unique data sets corresponding to the C time column. I want to create
separate .txt files of the combination C & D, C & E, C & F, ..., C & S.
A text file with 2 columns of data, C (Time) and one of D thru F
(data). Thanks.
 
N

Nikos Yannacopoulos

Here's the code you need:

Sub Export_Text_Files()
Dim lin As String
Range("C6").Select

For i = 1 To 16
Open "c:\temp\File" & i & ".txt" For Output As #1
For j = 0 To 143
lin = ActiveCell.Offset(j, 0).Value & ";"
lin = lin & ActiveCell.Offset(j, i).Value & ";"
Print #1, lin
Next
Close #1
Next

End Sub


You can easily change the path and produced file name, as
well as the field separator.

Nikos Y. (nyannaco at in dot gr)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top