View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Run-time error 9 - Subscript out of range (again)

the dollar sign and under_score may indicate that this code was meant to be
used with some assembly language code that isn't expecting the change to a
float variable. You may be cuasing a problem with passing the variable in
the stack to the assembly language routine (or possibly another language
like C language).

I would need to see more of the code, but I suspect the "RUN Structure TYPE"
is being used to pass the data to another program that isn't expecting the
Float type variable. the number of memory locations for a floating point
variable is different from a single or double type varaiable.

"packat" wrote:

I have searched far and wide and found several questions on subscript
out of range issue, but none of these questions seem to be similar to
mine. I am very new to VBA, so my vocabulary may not be standard...

I received an old spreadsheet application from a co-worker. When I
ran the macro that activate a VBA code, it ran fine and produce
correct results.


The problem occurs when I made changes to some of the data entries
(all floats) to tweak the model, I got the run-time error 9. The
changes are within the original range and of the same data type.
Since nothing else were changed (e.g. tab name, etc) so I assumed the
problem was not caused by typo as it seems to be the common source of
this error.


When I debug the code, I found

- The error occurred at line
Set w1 = ActiveWorkbook.Worksheets(Trim$
(run_.terminal_model_name))
where run_ is an object defined early on in the code.

- The value of "run_.terminal_model_name" was different from the
correct value when the model ran successfully. This suggests VBA was
confused and get the worksheet all mixed up.

Also, even when I undo the changes back to original, the code still
produce the same error.
I am refraining from posting he entire code since it is a bit large
and hard to read. Besides, I might have to discuss posting the code
to public forum with my co-worker who crated this code.

I am really stumped and would very much appreciate any idea of what
causes this problem and how to solve it.

pax
.