Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default Help with loop

Hello. I was hoping someone could make a monir edit to a small piece of
code I have. Thanks to Dick Kusleika, I have the following code that writes
the data on Sheet1 onto a text file. This works great, with one small
exception - There is an extra blank line at the bottom of the text file.
The text file is being used as an EDI transfer, and apparently the EDI is
very picky about extra blank lines! How can I edit the code so the extra
vbnewline is not added at the bottom?? Thanks so much!!

Sub SaveAsTextFile()

Dim sh As Worksheet
Dim rRow As Range
Dim rCell As Range
Dim sOutput As String
Dim lFnum As Long
Dim sFname As String

Set sh = Worksheets("Sheet1")

For Each rRow In sh.UsedRange.Rows
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Text & vbTab
Next rCell
sOutput = sOutput & vbNewLine
Next rRow

lFnum = FreeFile
sFname = "C:\Testfile.txt"

Open sFname For Output As lFnum

Print #lFnum, sOutput

Close lFnum

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Help with loop

Sub SaveAsTextFile()

Dim sh As Worksheet
Dim rRow As Range
Dim rCell As Range
Dim sOutput As String
Dim lFnum As Long
Dim sFname As String

Set sh = Worksheets("Sheet1")

For Each rRow In sh.UsedRange.Rows
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Text & vbTab
Next rCell
sOutput = sOutput & vbNewLine
Next rRow
sOutput = Left(sOutput, Len(sOutput) - 1)

lFnum = FreeFile
sFname = "C:\Testfile.txt"

Open sFname For Output As lFnum

Print #lFnum, sOutput

Close lFnum

End Sub

--
HTH

-------

Bob Phillips
"Steph" wrote in message
...
Hello. I was hoping someone could make a monir edit to a small piece of
code I have. Thanks to Dick Kusleika, I have the following code that

writes
the data on Sheet1 onto a text file. This works great, with one small
exception - There is an extra blank line at the bottom of the text file.
The text file is being used as an EDI transfer, and apparently the EDI is
very picky about extra blank lines! How can I edit the code so the extra
vbnewline is not added at the bottom?? Thanks so much!!

Sub SaveAsTextFile()

Dim sh As Worksheet
Dim rRow As Range
Dim rCell As Range
Dim sOutput As String
Dim lFnum As Long
Dim sFname As String

Set sh = Worksheets("Sheet1")

For Each rRow In sh.UsedRange.Rows
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Text & vbTab
Next rCell
sOutput = sOutput & vbNewLine
Next rRow

lFnum = FreeFile
sFname = "C:\Testfile.txt"

Open sFname For Output As lFnum

Print #lFnum, sOutput

Close lFnum

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Loop help PaulW Excel Discussion (Misc queries) 0 May 8th 06 04:00 PM
For/Loop skipping one value in loop only Matt Jensen Excel Programming 6 January 8th 05 12:03 PM
Worksheet_Change - loop within a loop bgm Excel Programming 1 January 19th 04 01:27 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 12:35 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"