UDF not recalculating

G

Gavin

I have the following two User Defined Functions in a module:

Public Function GetSheetIndex() As Long
Application.Volatile
GetSheetIndex = ActiveSheet.Index
End Function

Public Function GetSheetName(SheetIndex As Long) As String
Application.Volatile
GetSheetName = Sheets(SheetIndex).Name
End Function

In Cell A40 I have:
=GetSheetIndex()

and in Cell G40 I have:
=IF($A$40>1,INDIRECT(ADDRESS(ROW(G40),COLUMN(G40),,,GetSheetName($A$40-1)))+G39,G39)

What I'm trying to do is:
1. If the active sheet is the first in the workbook, then show th
value of cell G39 in cell G40.
2. If the active sheet is not the first in the workbook, then add cel
G39 from the active sheet to cell G40 of the previous sheet and show i
in cell G40 of the active sheet.

Excel does not recalculate the sheet index and the formula in G40 doe
not work even if the sheet index is calculated correctly.
Why won't this work? Have I done something stupid?

I actually would like to do this without any macro's or UDF's, but tha
does not seem possible (although it is dead easy in Lotus 1-2-3).

Thanks for any help or comments
Gavi
 

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