xll worksheet function

R

RB Smissaert

Been playing with UDF's in .xll add-ins and found that these are indeed much
faster than VBA UDF's.
In a moderately complex math function I found it about 30 times faster.

Just one thing I don't quite understand:
I have the xll function in B1 and the VBA function in C1
Now I copy both down to row 65536.
All cells in column B are calculatated in about 1 second,
except cell B1, which is done last. This is done after the last cell in
column C is done.
Swapping the columns (XLL in C and VBA in B) makes no difference.

Any suggestions why this and if anything can be done about it?

RBS
 
C

Charles Williams

Excel's default calculation sequence is to calculate the last cell entered
first (LIFO) and so on.

Note that VBA functions calculate much slower in Automatic mode than when in
manual and calculation is initiated from VBA (this is a VBE refresh bug).
see http://www.DecisionModels.com/Calcsecretsj.htm

It would be very interesting to get a timing comparison in manual using
Application.calculate.

Charles Williams
Decision Models
 
R

RB Smissaert

Yes, LIFO explained that one.

And indeed doing Application.Calculate is much faster indeed.
For the VBA UDF I had timings of about 25 seconds versus 5 seconds.
I hadn't been using UDF's in my app until a few weeks ago and I wasn't aware
of this.

So maybe I should do something like this:

Sub test()

Dim xlCalcMode As XlCalculation

With Application

'to retain the user's setting
xlCalcMode = .Calculation

.Calculation = xlManual

'run code

.Calculate

'return to the user's setting
.Calculation = xlCalcMode

End With

End Sub


RBS
 

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