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
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
This UDF return sheet number of active sheet
In any cell, input:PHP Code:
Function SheetNum() As Integer
SheetNum = ActiveSheet.Index
End Function
=sheetNum()
Quang PT
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
The following function slightly better mimics the original SHEET function available in Excel since version 2013:Artik![]()
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks