LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default write one column range to text avoiding final linebreak

Sub SaveColumnToText(ByVal txtFile As String, _
ByRef arr As Variant, _
Optional ByVal UBRow As Long = -1)

Dim R As Long
Dim hFile As Long
Dim sStr as String

If UBRow = -1 Then
UBRow = UBound(arr)
End If

hFile = FreeFile

Open txtFile For Output As hFile

For R = 1 To UBRow - 1
Write #hFile, arr(R, 1)
Next
sStr = Trim(arr(UBRow, 1).Text)
If Not IsNumeric(sStr) Then _
sStr = Chr(34) & sStr & Chr(34)
Print #hFile, sStr;
Close #hFile

End Sub

You may have to add some more if statements/code to get sStr to behave the
same as Write would (for dates perhaps), but this doesn't put in the vbCrLf

--
Regards,
Tom Ogilvy


"RB Smissaert" wrote in message
...
I tried several different methods. This is one of them:

Sub SaveColumnToText(ByVal txtFile As String, _
ByRef arr As Variant, _
Optional ByVal UBRow As Long = -1)

Dim R As Long
Dim hFile As Long

If UBRow = -1 Then
UBRow = UBound(arr)
End If

hFile = FreeFile

Open txtFile For Output As hFile

For R = 1 To UBRow
Write #hFile, arr(R, 1)
Next

Close #hFile

End Sub


RBS


"Tom Ogilvy" wrote in message
...
Why not post the code, then we don't have to go from scratch. I assume

you
are not using SaveAs, but are using low level file IO.

If not look at:


http://support.microsoft.com/default...62&Product=xlw
Working with Sequential Access Files


--
Regards,
Tom Ogilvy

"RB Smissaert" wrote in message
...
I need to write a one-column range to a text file.
This text file has to be all the cells separated by linebreaks.
So it has to come out like this:

Cell1
Cell2
Cell3
etc.

The problem I have is that I can't avoid the text file ending with a
linebreak.
So in the above example when the cursor in the text file is after

Cell3,
you
can
still move one line further by pressing the down key.
This last linebreak is causing problems when the textfile will be

written
back to an array.

Thanks for any advice on this.


RBS






 
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
In data range select final value. skydiving3 Excel Discussion (Misc queries) 2 August 7th 07 07:16 PM
Get final non-blank cell in range Eric Excel Worksheet Functions 9 October 19th 06 05:11 PM
AVOIDING DUPLICATES IN A RANGE OF CELLS Glint Excel Discussion (Misc queries) 11 August 9th 06 11:54 AM
In excel, how to put a linebreak in text in a cell TomStone Excel Discussion (Misc queries) 1 August 9th 05 10:21 PM
sum multiple criteria where final range is text? jt76 Excel Discussion (Misc queries) 0 May 25th 05 04:48 PM


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

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

About Us

"It's about Microsoft Excel"