How to save a copied data from an excel range as a text file.

P

Prasad Vanka

Hi,

I have copied data from a range in my sheet as Range("C1", "C" &
iCount + 1).Copy

I have a text file called data.txt which already contains data.

How can I clear data.txt and replace the data in it with the copied
data from the text file.

Thanks
 
C

crispbd

Try this instead:

Dim TextFileName As String
TextFileName = "C:\data.txt" ' replace this with path / filename o
text file


Open TextFileName For Output As #1 'as output will overwrite the file
For iCounter = StartRow to EndRow 'begin and end of range
Write #1, Cells(iCounter,3).Value 'write each valu
to the textfile
Next iCounter
Close #
 

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