"read" inputs past end of file

J

Japazo88

Hello everyone,

Lets say I have two programs written in excel that are used to automatically
select the right car for a person based on height, weight, etc. Both programs
do the same thing but the newer version has more inputs and outputs (saved to
a .txt) than the old one. My problem is that when trying to read the data
from the old saved files I get an "Input Past End of File" error. Basically
what I want to do is have the program read all the available data from the
text file then fill in the rest of the program input cells as blank. The
addition of more inputs wasnt taken into account when the old program was
written otherwise empty cells would have been written to allow for the new
inputs.

What is my best option for filling in blanks once Ive reached the end of the
..txt file?

Thanks in advance!
 
J

Joel

Why don't you clear the cells before reading in the text file. The program
should only read in the data from the text files and the other cells will
remain blank.
 
J

Japazo88

Well, what happens is the program uses a userform to create a .txt savefile
and writes all the user inputs line by line.

Open strFile For Output As #2
Write #2, Sheets("example").Range("a1")
Write #2, Sheets("example").Range("a2")
Write #2, Sheets("example").Range("a3")
etc...

then, when I want to open one of the old savefiles it begins the same
process in reverse,

Open strFile For Input As #2
Input #2, a1
Sheets("example").Range("a1") = a1
Input #2, a1
Sheets("example").Range("a2") = a1
Input #2, a1
Sheets("example").Range("a3") = a1

etc...

The problem arises when the Macro hits the EOF of the savefile. It has a
line that says

Input #2, a1
Sheets("example").Range("a500") = a1

when a500 was never saved in the old program's output file. So what I want
to do in order to do away with one macro for opening old files and one macro
for opening new ones is to basically say,

if eof then
input #2 = ""

so that it can read until the end of the file then input blanks after that.
Does that make more sense?
 
J

Joel

then re-arrange your loop

Open strFile For Input As #2
for i = 1 to 500 '<=change to you r actual last row
if eof(2) then
Sheets("example").Range("a" & i) = ""
else
Input #2, a1
Sheets("example").Range("a" & i) = a1
end if
next i
 
J

Japazo88

The only problem that I see here is that my data doesnt fill sheet1 range
(a1:aXX). My data is in specific cells on multiple pages but I think this is
enough information to allow me to get what I need done. Ill update whether or
not this works soon.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top