+ Reply to Thread
Results 1 to 4 of 4

Sheet function VBA for older excel versions

Hybrid View

Michael be stumped Sheet function VBA for older... 03-18-2024, 03:21 PM
bebo021999 Re: Sheet function VBA for... 03-18-2024, 10:12 PM
jindon Re: Sheet function VBA for... 03-19-2024, 01:24 AM
Artik Re: Sheet function VBA for... 03-19-2024, 06:43 PM
  1. #1
    Registered User
    Join Date
    03-18-2024
    Location
    Arkansas
    MS-Off Ver
    2007
    Posts
    7

    Sheet function VBA for older excel versions

    I have only a very cursory understanding of VBA and I'm working in Excel 2007. Can someone please help me with a UDF that will provide me with the SHEET function as it works in the current Excel versions?

    Thank you in advance

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,648

    Re: Sheet function VBA for older excel versions

    This UDF return sheet number of active sheet

    PHP Code: 
    Function SheetNum() As Integer
    SheetNum 
    ActiveSheet.Index
    End 
    Function 
    In any cell, input:
    =sheetNum()
    Quang PT

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Sheet function VBA for older excel versions

    SHEET Function
    Function SHEET(Optional s As String)
        Dim m As Name
        If s = "" Then SHEET = Application.Caller.Parent.Index: Exit Function
        For Each m In ThisWorkbook.Names
            If LCase$(m.Name) = LCase$(s) Then SHEET = Range(m.Name).Parent.Index: Exit Function
        Next
        If Evaluate("isref('" & s & "'!a1") Then SHEET = Sheets(s).Index: Exit Function
        SHEET = CVErr(2029)
    End Function

  4. #4
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,532

    Re: Sheet function VBA for older excel versions

    The following function slightly better mimics the original SHEET function available in Excel since version 2013:
    Function Sheet2003(Optional vValue As Variant) As Variant
        Dim LO As ListObject
        
        On Error Resume Next
        Set LO = vValue.ListObject
           
        If IsMissing(vValue) Then
            Sheet2003 = ActiveSheet.Index
        ElseIf IsError(vValue) Then
            Sheet2003 = CVErr(Split(CStr(vValue))(1))
        ElseIf Evaluate("ISREF('" & vValue & "'") Then    'borrowed from jindon :)
            Sheet2003 = vValue.Parent.Index
            If IsEmpty(Sheet2003) Then
                If Evaluate("ISREF('" & vValue & "'!A1") Then
                    Sheet2003 = Application.Range("'" & vValue & "'!A1").Parent.Index
                Else
                    Sheet2003 = CVErr(xlErrNA)
                End If
            End If
        ElseIf Not LO Is Nothing Then
            Sheet2003 = LO.Range.Parent.Index
        End If
        
    End Function
    Artik

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Convert XLOOKUP Function to Work with Older Excel Versions
    By MCC_16 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 09-17-2021, 10:19 AM
  2. MinIFS() for older versions of excel help.
    By MarvinP in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 08-31-2020, 01:09 AM
  3. [SOLVED] Sort problem with older versions of excel
    By scrabtree23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2020, 03:55 PM
  4. Simulating conditions of older Excel versions
    By chengafni in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2016, 10:21 AM
  5. Drop-down lists in older versions of Excel
    By nclark52 in forum Excel General
    Replies: 1
    Last Post: 09-29-2015, 05:52 PM
  6. [SOLVED] Using Older versions of ms excel with 2003
    By BassJay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2005, 02:05 PM
  7. Older versions of Excel
    By Jaygirl44 in forum Excel General
    Replies: 0
    Last Post: 05-13-2005, 06:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1