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

  • Thread starter Thread starter Prasad Vanka
  • Start date Start date
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
 
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 #
 
Back
Top