+ Reply to Thread
Results 1 to 7 of 7

VBA: Search for table named 'x', then change name

  1. #1
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    VBA: Search for table named 'x', then change name

    Hello,

    I want to write a code that searches my workbook for a table named 'DATA_CONSOL' then changes the name of that table to 'DATA_CONSOL_OLD'.
    (ideally, the code would work so that if I run it multiple times, the first time it would rename the existing table to DATA_CONSOL_OLD, and the second time it would rename it to a unique name (e.g. DATA_CONSOL_OLD_2), then so on and so forth. However, if there is no table named 'DATA_CONSOL' in the workbook, it'd move to the next action in the code (since there'd be nothing to rename)
    Is this possible?

    Context (if you care):
    I have a code that creates a table, and names it 'DATA_CONSOL'. And I want to adjust my code so that the most recently created table is always named 'DATA_CONSOL'. This way I can reference it via formulas and not have to worry about it pulling outdated data since the most recent macro run will always produce a table named 'DATA_CONSOL'. The code is written, I just need to add these lines to make it that much better.

    This would be a HUGE help!

    Thank you!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA: Search for table named 'x', then change name

    Will the table(s) be on a specific sheet or could it be on any sheet within the workbook?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Re: VBA: Search for table named 'x', then change name

    Quote Originally Posted by Norie View Post
    Will the table(s) be on a specific sheet or could it be on any sheet within the workbook?
    I could be on any sheet
    (every time a table is made the macro creates a new sheet w/ a unique name)

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA: Search for table named 'x', then change name

    Why don't you rename the last table made before creating the new table?

  5. #5
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Re: VBA: Search for table named 'x', then change name

    Quote Originally Posted by Norie View Post
    Why don't you rename the last table made before creating the new table?
    Hoping I can insert code to automate this so that I dont need to manual change a table's name to a unique one every time i wanna run the macro
    Is this possible?
    Thanks!

  6. #6
    Forum Contributor
    Join Date
    11-10-2011
    Location
    New York, NY
    MS-Off Ver
    MS Office: Excel 365
    Posts
    163

    Re: VBA: Search for table named 'x', then change name

    Quote Originally Posted by Norie View Post
    Why don't you rename the last table made before creating the new table?
    nevermind, figured it out:

    On Error Resume Next
    Application.Goto Reference:="DATA_CONSOL"
    ActiveSheet.ListObjects("DATA_CONSOL").Name = "DATA_CONSOL_OLD"

    Thanks!

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA: Search for table named 'x', then change name

    Glad you got a solution.

    PS I wasn't suggesting doing what I suggested in post #4 manually.

+ 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. VBA - change all pivot table data sources to named range
    By sportsnut898 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2016, 02:26 PM
  2. VBA to test if a cell is contained in a specific named column in a named table?
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-14-2015, 05:34 PM
  3. Conditional format with search, vlookup and named Table
    By jed38 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-09-2014, 04:18 PM
  4. [SOLVED] Search in named tab dependent on cell value [SOLVED]
    By gogita in forum Excel General
    Replies: 2
    Last Post: 09-12-2013, 09:43 AM
  5. Array formulas referencing a named range or named table
    By anrichards22 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-03-2013, 11:59 PM
  6. search named ranges with user input
    By KrZyMiC in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-16-2011, 07:15 PM
  7. Use value in Named cell to search for text
    By Un-Do Re-Do in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2009, 09:15 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