Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write to txt file WITHOUT quotes?

Status
Not open for further replies.

peach255

Programmer
Jan 20, 2003
29
US
I have the following code which I write teh values from a range in Excel to a txt file. However, it's writes the values back w/ quotes (") around the values. If I add the code : If IsNumeric(vData) then vData = Val(vData), this would get rid of my leading zeros in my values. For ex, 00012345 would be written to the txt file as 12345. The leading zeros are important to me, so I would like to keep it. Is there a way to get rid of the quotes around the values and keep the leading zeros?I have the following code so far:
Dim ExpRange As Range
Set ExpRng = ActiveCell.CurrentRegion
FirstCol = ExpRng.Columns(1).Column
LastCol = FirstCol + ExpRng.Columns.Count - 3
FirstRow = ExpRng.Rows(1).Row
LastRow = FirstRow + ExpRng.Rows.Count - 3

Open "C:\textfile.txt" For Output As #1
For r = FirstRow To LastRow
For c = FirstCol To LastCol
vData = ExpRng.Cells(r, c).Value
If IsNumeric(vData) Then vData = Val(vData)
If c <> LastCol Then
Write #1, vData;
Else
Write #1, vData
End If
Next c
Next r

Close #1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top