+ Reply to Thread
Results 1 to 2 of 2

Display Worksheet name and Refers To Range for tables

Hybrid View

  1. #1
    Registered User
    Join Date
    03-01-2012
    Location
    Nottingham, England
    MS-Off Ver
    Excel 2010
    Posts
    64

    Display Worksheet name and Refers To Range for tables

    Hello folks

    I've got two User Defined Functions (see below) that give me the Worksheet and Refers To range for a list of named ranges in my workbook. However these only work for Defined Names and not Tables. What should I do to amend these UDFs so that I also get the Worksheet and Refers To Range info for tables please?


    Function NamedRangeAddress(ByVal sName As String) As String
        On Error Resume Next
            NamedRangeAddress = Application.ActiveWorkbook.Names(sName).RefersTo
    End Function
    
    Function NamedRangeWorksheet(ByVal sName As String) As String
        On Error Resume Next
            NamedRangeWorksheet = Application.ActiveWorkbook.Names(sName).RefersToRange.Worksheet.Name
    End Function
    Thanks
    Kenny

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Display Worksheet name and Refers To Range for tables

    Try this:

    Function Table_Range(TableName As String) As String
    Dim sh As Worksheet             ' Pointer to sheets in the workbook
    Dim lo As ListObject            ' Pointer to list objects on the sheet
    Dim tbl As ListObject           ' Pointer to the table
    Dim SheetName As String         ' Sheet name on which the table was found
    
    ' Loop though each sheet
    For Each sh In ActiveWorkbook.Sheets
        ' Loop through list objects on the sheet
        For Each lo In sh.ListObjects
            ' If the list object name = the table name return sheet name and table address
            If lo.Name = TableName Then
                SheetName = sh.Name
                Set tbl = sh.ListObjects(TableName)
                Table_Range = "'" & SheetName & "'!" & tbl.Range.Address
                Exit Function
            End If
        Next lo
    Next sh
    
    Table_Range = "Table not found"
    
    End Function
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. Add column which refers to a worksheet
    By A[L]C in forum Excel Charting & Pivots
    Replies: 9
    Last Post: 12-12-2013, 10:27 AM
  2. Forumla which refers to a cell which refers to a sheet name
    By awiller2 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 12-03-2012, 09:57 PM
  3. Pivot tables: display filtered data in another worksheet
    By ridingbio in forum Excel General
    Replies: 5
    Last Post: 12-12-2011, 12:22 AM
  4. Replies: 5
    Last Post: 07-27-2010, 10:58 AM
  5. creating named range in workbook that refers to VBA range
    By twd000 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2008, 05:42 PM
  6. Access a worksheet level named range with Refers To like "=5".
    By Jeremy Gollehon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2006, 06:10 PM
  7. Named Range Refers To
    By Tim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2006, 11:00 PM
  8. toggling which worksheet a named range refers to
    By Loftus in forum Excel General
    Replies: 0
    Last Post: 03-29-2005, 08:06 PM

Tags for this Thread

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