Excel 2007: UDF can't reference row below 65536

G

Greg Lovern

In Excel 2007 (I'm on SP2), if I enter this formula:

=SUM(A65537)

It works fine. But if I enter this formula:

=MYUDF(A65537)

Excel turns it into this:

=MYUDF(#REF!)


That isn't the UDF's fault' Excel is doing that before the UDF has the
opportunity to do anything at all. Is there a workaround or fix?


Thanks,

Greg
 
T

Tom Hutchins

It sounds like you are working in Compatibility Mode. How many rows does your
workbook have on a sheet? I created a simple MyUDF function, and it accepts
any range up to 1048576 unless the workbook calling it was saved in an
earlier Excel format (.xls instead of .xlsx).

Hope this helps,

Hutch
 
G

Greg Lovern

Hi Tom,

I'm in a .xlsx saved out from Excel 2007 as a standard Excel .xlsx
file. The last cell is XFD1048576.

I've been working with it more and found that the problem was not as
simple as I'd thought.

The problem seems to require that the UDF have two arguments (both
required args). Then, the problem happens even if only one arg is
passed, which is invalid for the UDF but even so, the reference in the
formula shouldn't change to #REF!.

So to get a simple repro, change the UDF to require two args, then
reference cells below row 65536 in those args:

MYUDF(A65537,A65537)


Result: Excel changes the formula to:

MYUDF(#REF!,A65537)


Any thoughts?


BTW I've been working with UDFs in an .xla that has stubs that call an
ActiveX DLL. I'll see if I get the same problem with a simpler
scenario. Come to think of it, the .xla is in Excel 97-2003 format
(for compatibility with those Excel versions).


Thanks,

Greg
 
G

Greg Lovern

I've found that if I go into the .xla and comment out the call to the
DLL, and just add the two references together, it works fine. So I'm
going to have to step through the DLL next, which I don't have with me
at the moment.

No matter what the DLL might be doing wrong, Excel shouldn't change
the formula like that. Any error should be returned as the return
value, not as a change to the formula itself. Are there any
circumstances under which Excel is expected to change the formula when
just calculating the formula?


Thanks,

Greg
 
T

Tom Hutchins

You hadn't mentioned any .DLL or .xla files. I think that one (or both) of
them must be based on an Excel 2003 or earlier format. Is the 65636-row limit
hard-coded in the DLL? Even though your current workbook is in Excel 2007
format, the UDF (and it sounds like the .DLL is the culprit) still has the
limitations of XL2003. The .DLL and .xla files need to be rewritten/recreated
in an XL2007-compatible format.

Hutch
 
R

Ron Rosenfeld

BTW I've been working with UDFs in an .xla that has stubs that call an
ActiveX DLL. I'll see if I get the same problem with a simpler
scenario. Come to think of it, the .xla is in Excel 97-2003 format
(for compatibility with those Excel versions).

Try it in an .xlam, which is the Excel 2007 version of the .xla

FWIW, your problem does not reproduce in my Excel 2007.

--ron
 
G

Greg Lovern

When I got home last night, I tried it again, to work on a workaround
until I have a chance to find and fix the bug. To my surprise, it did
NOT repro on my home computer! When I got back here this morning, I
verified that it does repro here.

On both computers, I'm running Excel 2007 SP2, and I was using the
same version of my add-in, with the xla and dll both installed by the
same release package. To repro the problem, in both cases I was using
the same sample .xlsx file.

I have no idea why it works on one computer and not the other.


Greg
 
G

Greg Lovern

Sorry, I forgot to add:

If the problem only occured on one computer, I'd be inclined to think
it was a problem with the Excel installation on that computer. But the
problem exists on at least two computers -- the problem was originally
reported to me by a customer, and it was his sample .xlsx file I used
on both of my computers to repro.

So the problem happens on his computer and one of mine, but not on
another computer of mine.

Greg
 
R

Ron Rosenfeld

When I got home last night, I tried it again, to work on a workaround
until I have a chance to find and fix the bug. To my surprise, it did
NOT repro on my home computer! When I got back here this morning, I
verified that it does repro here.

On both computers, I'm running Excel 2007 SP2, and I was using the
same version of my add-in, with the xla and dll both installed by the
same release package. To repro the problem, in both cases I was using
the same sample .xlsx file.

I have no idea why it works on one computer and not the other.


Greg

Try saving the file as an .xlsm file.
--ron
 
R

Ron Rosenfeld

Sorry, I forgot to add:

If the problem only occured on one computer, I'd be inclined to think
it was a problem with the Excel installation on that computer. But the
problem exists on at least two computers -- the problem was originally
reported to me by a customer, and it was his sample .xlsx file I used
on both of my computers to repro.

So the problem happens on his computer and one of mine, but not on
another computer of mine.

Greg

I think it has to do with compatibility mode incompatibilities.
--ron
 
G

Greg Lovern

It stopped reproducing here after I restarted Excel. I tried several
different ways but haven't been able to get the problem to happen
again. I'll pick it up again if I can get a repro. Also, when I can
get the time I'll step through the DLL function to see if I can find
the problem. But the .xla is just passing values to the DLL, not range
references.

Greg
 

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