View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default write one column range to text avoiding final linebreak

Just found one method that seems to do what I want:

Sub ColumnRangeToText(ByRef rngCol As Range, ByVal strFile As String)

Dim strRange As String
Dim arr
Dim LR As Long
Dim i As Long
Dim hFile As Long

arr = rngCol
LR = UBound(arr)

For i = 1 To LR - 1
strRange = strRange & arr(i, 1) & vbCrLf
Next

strRange = strRange & arr(LR, 1)

hFile = FreeFile
Open strFile For Output As hFile

Print #hFile, strRange;
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