Export to text file

Mlbblue

New Member
Joined
Oct 8, 2006
Messages
20
Hey - quick question - I need to write a macro that will export a list of values in a single column (column A for example) to a text file delimited by a ;

I thought I could do this without a macro but so far haven't found it... any help appreciated!

Cheers

Mark
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Just to clarify:

In column A I have:

trade1
trade2
trade3

I'm trying to export this to a text file as:

trade1;trade2;trade3

I'm really stuck on this - any help would be really really appreciated! :)
 
Upvote 0
Hi,

Try

Code:
Dim a as integer
Dim strTextFileName As String

'CHANGE c:\newFile.txt TO YOUR FILE LOCATION AND NAME
strTextFileName = "c:\newFile.txt"
Dim intHandle As Integer
intHandle = FreeFile

'THIS PART CHECKS IF THE FILE ALREADY EXISTS, IF IT IS IT OPENS IT AND ADDS TO IT IF IT DOESN'T EXIST IT CREATES IT

If Dir(strTextFileName) = "" Then
    Open strTextFileName For Output As #intHandle
Else
    Open strTextFileName For Append As #intHandle
End If

For a=1 to 3 'CHANGE THIS AREA TO THE ROW START AND ROW END
      Print #intHandle, sheets("sheet1").range("a" & a); ";";
Next a

Close #intHandle

HTH
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top