+ Reply to Thread
Results 1 to 9 of 9

How to get the name of the table in a cell with a function?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-15-2015
    Location
    Tehran
    MS-Off Ver
    2013
    Posts
    19

    How to get the name of the table in a cell with a function?

    Hi
    I have made a database in excel with different sheets. each sheet has got one table in it. there is a "summary" sheet that I have summarized the data of all sheets in that.
    I need to know the name of each table in each sheet automatically. I mean I want to use a function to extract the name of table in each sheet. I searched all of the functions but I did not find any related function. I will be appreciated if somebody can help me.
    Best Regards
    Rsdoost

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: How to get the name of the table in a cell with a function?

    indirect________________

  3. #3
    Registered User
    Join Date
    09-15-2015
    Location
    Tehran
    MS-Off Ver
    2013
    Posts
    19

    Re: How to get the name of the table in a cell with a function?

    thanks for your reply
    but I did not get it
    Indirect function refers to cell address not name of table.
    regards

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: How to get the name of the table in a cell with a function?

    Quote Originally Posted by rsdoost View Post
    Indirect function refers to cell address not name of table
    Nope, You can use Table name too:
    Formula: copy to clipboard
    =INDIRECT("Table1")
    etc.

    But this is the opposite direction - As I understand, you want to retrieve name of table. So my proposition is to use simple UDF:
    Function firsttable(sheetname As String) As String
    Dim dummystr As String
    On Error Resume Next
      dummystr = Worksheets(sheetname).Name
      If Err.Number <> 0 Then
        firsttable = "! no worksheet: " & sheetname
        Exit Function
      End If
    On Error GoTo 0
    If Worksheets(sheetname).ListObjects.Count = 0 Then
      firsttable = "! no table in worksheet: " & sheetname
    Else
      firsttable = Worksheets(sheetname).ListObjects(1).Name
    End If
    End Function
    Insert this code in standard module (<Alt>+<F11> <Alt>+<I>,<M> ), make sure your spreadsheet has macros enabled and use as you would use any standard excel function in a worksheet. For instance:
    Formula: copy to clipboard
    =firsttable("Sheet4")
    Best Regards,

    Kaper

  5. #5
    Registered User
    Join Date
    09-15-2015
    Location
    Tehran
    MS-Off Ver
    2013
    Posts
    19

    Re: How to get the name of the table in a cell with a function?

    hi
    thank you for your reply
    but I want to do that without vb or macro.
    for example we use the following function for finding name of sheet.

    =RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1),1))

    I am looking for similar function for name of table.
    regards

  6. #6
    Registered User
    Join Date
    09-15-2015
    Location
    Tehran
    MS-Off Ver
    2013
    Posts
    19

    Re: How to get the name of the table in a cell with a function?

    hi everybody
    I did it myself
    thx

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: How to get the name of the table in a cell with a function?

    Great,
    Please share your solution here for those who will look for it by http://www.excelforum.com/search.php etc.

  8. #8
    Registered User
    Join Date
    09-15-2015
    Location
    Tehran
    MS-Off Ver
    2013
    Posts
    19

    Re: How to get the name of the table in a cell with a function?

    correction
    ---------------------------
    hi
    suppose , there is a table in the sheet1 with headers column1,column2,... and cells A1, A2 and A3 are blank.
    you can write a formula in A1 that is about table such as
    =COUNTIF(Table1[column1],TRUE)

    then you can write the following function in cell A2
    =FORMULATEXT(A1)

    at the end you can write this in cell A3
    =MID(A2,FIND("(",A2,1)+1,FIND("[",A2,1)-FIND("(",A2,1)-1)

    you will see the cell "A3" has got the name of table.

    if you change the name of table manually in formula --> Name Manager then the content of cell "A3" will be changed.
    regards

  9. #9
    Registered User
    Join Date
    09-15-2015
    Location
    Tehran
    MS-Off Ver
    2013
    Posts
    19

    Re: How to get the name of the table in a cell with a function?

    hi
    suppose , there is a table in the sheet1 with headers column1,column2,... and cells A1, A2 and A3 are blank.
    you can write a formula in A1 that is about table such as
    =COUNTIF(Table1[TRUE],TRUE)

    then you can write the following function in cell A2
    =FORMULATEXT(A1)

    at the end you can write this in cell A3
    =MID(E5,FIND("(",A2,1)+1,FIND("[",A2,1)-FIND("(",A2,1)-1)

    you will see the cell "A3" has got the name of table.

    if you change the name of table manually in formula --> Name Manager then the content of cell "A3" will be changed.
    regards

+ 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. Replies: 11
    Last Post: 10-30-2014, 05:06 PM
  2. Replies: 7
    Last Post: 08-08-2014, 11:01 AM
  3. Replies: 5
    Last Post: 06-01-2014, 04:54 PM
  4. Help creating vba function to move data from table to table on if condtion
    By damaple in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2013, 05:42 AM
  5. Replies: 0
    Last Post: 07-02-2013, 11:30 AM
  6. Replies: 5
    Last Post: 12-19-2012, 11:05 AM
  7. Replies: 2
    Last Post: 02-15-2005, 10:58 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