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
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