Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print#1 Last row is empty 1

Status
Not open for further replies.

Flippertje

Technical User
Mar 12, 2004
118
NL
I have the following code:

open "C:\test.txt" for output as #1
for i = 1 to y
print #1, cells(y,1)
next
close #1

The idea is to print some rows to a text file. The last row of the textfile is always empty. Not because the last entry is emtpy but using print it seems to insert the rows in the new textfile rather than paste over the existing standard row.
Does anyone know how to delete this last row form Excel VBA or how to this antoher way so that the last row is not empty?

Many thanks!

Flippertje
 
Feels a bit odd, using the English language as we are both coming from the Netherlands.
Anyway, concerning your problem.
Does variable y have the right value? I used your code and everything seems fine in Notepad. New line starts right under the last copied line.

ries
 
Ha Ries,

y is just a way to print each row into the the textfile.
E.g. i have 5 rows to print to a textfile (must be .txt) it will come out like this:

1
2
3
4
5

After the 5 an enter exists so that the cursor is on the next row. That's my problem.

Can you solve it?
 
Surely outputting to text files in this way, every line is temrinated by a CrLf ( carriage return/line feed )?



Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Before we all go any further, can you explain why you want the last row to be different?

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 


I'd venture to state that the last record is NOT empty.

For instance, can you open the file in NotePad and select ANYTHING in what looks like the blank row?

Probably NOT, for the reasons stated in the previous posts.

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
The last return has to go because the file is used by a program i have no admin rights for. That program won't import the file if the last line has a return.

Tnx for all you're trouble !

Flippertje
 

Then just make your loop go to Y+1

Skip,
[sub]
[glasses] [red]Be Advised![/red]
The band of elderly oriental musicians, known as Ground Cover, is, in reality...
Asian Jasmine![tongue][/sub]
 
And what about something like this ?
y = 5
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\test.txt", True)
For i = 1 To y - 1
MyFile.WriteLine Cells(i, 1)
Next
MyFile.Write Cells(y, 1)
MyFile.Close

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The last line isn't written. It's the return that already exists when one uses print#1. Like i said, it inserts the line above the return. So is there a way eg to open the textfile and then remove that last return?

My english osnt that great so trying to explain the problem is hard it seems:))

Many thanks for your patience!

Flippertje
 
Please try PHVs code!!!!

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top