How to read a string in excel and include the single quote

R

Ricky

I have the following value in a cell:
'TEST14','TEST15','TEST16'

When printing this value to a TXT file, I get:
TEST14','TEST15','TEST16'

How do I get to include the single quote that occurs in the beginning
of the string to be included in the output? Please help.

My code:

Sub Testme
Sheets("sheet01").Activate
gOutfile = "c:/test.txt"
Open gOutfile For Output As #1
For r = 1 To 30
xData = Cells(r, 1).Value
Print #1, xData
Next r
End Sub
 
M

Mike H

Ricky,

It works fine for me but I do have 1 comment, you must close the file

Sub Testme()
Sheets("sheet01").Activate
gOutfile = "c:/test.txt"
Open gOutfile For Output As #1
For r = 1 To 30
xData = Cells(r, 1).Value
Print #1, xData
Next r
Close #1
End Sub

Mike
 
S

Susan

put it back in............

Sub Testme
Sheets("sheet01").Activate
gOutfile = "c:/test.txt"
Open gOutfile For Output As #1
For r = 1 To 30
xData = "'" & Cells(r, 1).Value '<---- change
Print #1, xData
Next r
End Sub


see if that works. i didn't test it.
:)
susan
 
A

Atishoo

Hi ricky
yes i get the same result just using a simple line to test as follows

ActiveCell.Value = Range("b3").Value
 

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