Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Excel to txt

I have a sheet set up with 2 columns of data (both numerical) and I am
using the code listed below to extract into a txt file, which works
fine.

0000000011000+00030+
0000000051000+00030+
8711000055380+00030+
8711000075371+00030+
8888021100013+00030+
etc etc etc

What I need to do is extract the data into a txt file which looks like

0000000011000+00030+0000000051000+00030+8711000055 380+00030+8711000075371+00030+
8888021100013+00030+ etc etc etc

I have not had experience before extracting from excel into a text file
and would appreciate some pointers.

Thanks,
Dean

Here is the code I have been testing (www.mcgimpsey.com)


Const DELIMITER As String = "+"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "Test.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, Columns.Count).End(xlToLeft))
sOut = sOut & DELIMITER & myField.Text
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Excel to txt

Not that I've tested it but wouldn't you just move the Print statement out
of the loop to below the Next? Getting rid of the sOut=empty needless to
say.

--
Jim
"Ledge" wrote in message
oups.com...
|I have a sheet set up with 2 columns of data (both numerical) and I am
| using the code listed below to extract into a txt file, which works
| fine.
|
| 0000000011000+00030+
| 0000000051000+00030+
| 8711000055380+00030+
| 8711000075371+00030+
| 8888021100013+00030+
| etc etc etc
|
| What I need to do is extract the data into a txt file which looks like
|
|
0000000011000+00030+0000000051000+00030+8711000055 380+00030+8711000075371+00030+
| 8888021100013+00030+ etc etc etc
|
| I have not had experience before extracting from excel into a text file
| and would appreciate some pointers.
|
| Thanks,
| Dean
|
| Here is the code I have been testing (www.mcgimpsey.com)
|
|
| Const DELIMITER As String = "+"
| Dim myRecord As Range
| Dim myField As Range
| Dim nFileNum As Long
| Dim sOut As String
|
| nFileNum = FreeFile
| Open "Test.txt" For Output As #nFileNum
| For Each myRecord In Range("A1:A" & _
| Range("A" & Rows.Count).End(xlUp).Row)
| With myRecord
| For Each myField In Range(.Cells(1), _
| Cells(.Row, Columns.Count).End(xlToLeft))
| sOut = sOut & DELIMITER & myField.Text
| Next myField
| Print #nFileNum, Mid(sOut, 2)
| sOut = Empty
| End With
| Next myRecord
| Close #nFileNum
| End Sub
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Excel to txt

If you put a semicolon after your print # statement, it suppresses the
CR LF.

Print #nFileNum, Mid(sOut, 2);

Len


Ledge wrote:
I have a sheet set up with 2 columns of data (both numerical) and I am
using the code listed below to extract into a txt file, which works
fine.

0000000011000+00030+
0000000051000+00030+
8711000055380+00030+
8711000075371+00030+
8888021100013+00030+
etc etc etc

What I need to do is extract the data into a txt file which looks like

0000000011000+00030+0000000051000+00030+8711000055 380+00030+8711000075371+00030+
8888021100013+00030+ etc etc etc

I have not had experience before extracting from excel into a text file
and would appreciate some pointers.

Thanks,
Dean

Here is the code I have been testing (www.mcgimpsey.com)


Const DELIMITER As String = "+"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "Test.txt" For Output As #nFileNum
For Each myRecord In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, Columns.Count).End(xlToLeft))
sOut = sOut & DELIMITER & myField.Text
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"