B
Brettjg
Hi, I have the following Public Function in a non-object module, and for the
most part it works perfectly. However, when I run a macro (or something else
happens that I can't define just yet) the cells using the function return
#VALUE (when they previously had the correct values in them - and nothing
else to do with them has changed. Simply copy & paste the cel with the
function in it does nothing. I have to actually copy & paste the formula for
the cell in the formula bar at the top and then the value returns to normal.
The code is:
Public Function FX_EXISTING(num)
Dim cnt As Integer, cntfx As Integer, fx_pos(10) As Integer
cnt = 1: cntfx = 0
Do Until cntfx = num
If Range("FX.REFI").Offset(cnt, 0) > 0 Then
cntfx = cntfx + 1
fx_pos(cntfx) = cnt
End If
cnt = cnt + 1
If cnt > 10 Or cntfx = num Then: Exit Do
Loop
If cntfx = num Then: FX_EXISTING = Range("FX.REFI").Offset(fx_pos(num),
-23).Value
'Sheets("LOANS").Calculate
End Function
I had a suspicion that the Calculate at the end may have mad it play up so I
commented that out, but it didn't help (it's probably not necessary anyway).
Regards, Brett
most part it works perfectly. However, when I run a macro (or something else
happens that I can't define just yet) the cells using the function return
#VALUE (when they previously had the correct values in them - and nothing
else to do with them has changed. Simply copy & paste the cel with the
function in it does nothing. I have to actually copy & paste the formula for
the cell in the formula bar at the top and then the value returns to normal.
The code is:
Public Function FX_EXISTING(num)
Dim cnt As Integer, cntfx As Integer, fx_pos(10) As Integer
cnt = 1: cntfx = 0
Do Until cntfx = num
If Range("FX.REFI").Offset(cnt, 0) > 0 Then
cntfx = cntfx + 1
fx_pos(cntfx) = cnt
End If
cnt = cnt + 1
If cnt > 10 Or cntfx = num Then: Exit Do
Loop
If cntfx = num Then: FX_EXISTING = Range("FX.REFI").Offset(fx_pos(num),
-23).Value
'Sheets("LOANS").Calculate
End Function
I had a suspicion that the Calculate at the end may have mad it play up so I
commented that out, but it didn't help (it's probably not necessary anyway).
Regards, Brett