View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
John Hutcins John Hutcins is offline
external usenet poster
 
Posts: 19
Default Add-In Public Function Recalc Problem

Niek,
Here is an example of one of the functions.

Public Function GpBr2Dept(Group, Branch)
FindName 'this is a sub that identifies the addin name in case it is renamed
when installed
Test2GpBr2Dept 'this is a sub that calls a private sub that loads and sorts
an array if it is not already loaded
Dim i As Long
Dim UB As Long
Dim GpBr As String
GpBr = UCase(Branch)
If Len(GpBr) = 1 Then GpBr = "0" & GpBr
GpBr = UCase(Group) & GpBr
If Len(GpBr) = 3 Then GpBr = "0" & GpBr

UB = UBound(BrData)

Dim Y As Long
Dim X As Long
Y = UB
i = 1
Do Until Y - i <= 10
X = Round((Y - i) / 2, 0)
If BrData(i + X, 1) GpBr Then
Y = Y - X
Else
If BrData(i + X, 1) < GpBr Then
i = i + X
Else
Y = Y - X + 1
End If
End If
Loop

For ii = i To Y
If BrData(ii, 1) = GpBr Then
GpBr2Dept = BrData(ii, 2)
ii = Y
End If
Next ii
End Function

The function is looking up a translation value in a table stored in the
addin. I'm using an array because I can get it to run faster than a VLookUp.
If I use VLookup and copy down 1,000 rows it takes forever. Once the array
loads and sorts for the 1st formula copying down 1,000 times runs very fast.

I didn't copy in all of the other code called from the function. I can do
that if it will help. But, there is a lot of it.

Thanks for looking into this,
John

"Niek Otten" wrote:

Hi John,

What do the functions look like and how are they called? Is Calculation set
to Automatic?

--
Kind regards,

Niek Otten

"John Hutcins" wrote in message
...
I have written an add-in with several public functions that work fine when
used in a formula in a cell. But, when I save the workbook, close Excel,
reopen Excel and open the workbook the formulas evaluate to #VALUE!. If I
hit recalc it does nothing. If I reenter a formula or enter a formula in
a
new cell it works fine. How do I get the add-in to run my functions and
show
the result when it Excel opens or when a new workbook opens?

Thanks,
John Hutchins