Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to integrate User Defined Function with excel formula

The following User Defined Function is referencing previous excel sheet.

Function PrevSheet()
    Application.Volatile
    PrevSheet = Worksheets(ActiveSheet.Index - 1).Name
End Function

The following formula is okey.

=Sheet1!A1

The following formula is NOT okey. The following formula needs to repaired.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

=PrevSheet()!A1

>Solution :

Expansion on my comment to do this all in a UDF:

Function PrevSheetVal(PrevSheetRow As Long, PrevSheetCol As Long) As String
    Application.Volatile
    PrevSheetVal = Worksheets(ActiveSheet.Index - 1).Cells(PrevSheetRow, PrevSheetCol).Value
End Function

Used like:

=PrevSheetVal(1,1)

Which will return the value in cell A1 of the "Previous sheet" as defined by the sheet with an index 1 less than the Activesheet

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading