+ Reply to Thread
Results 1 to 9 of 9

VBA Table reference if working with a copy of the table

  1. #1
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    VBA Table reference if working with a copy of the table

    Hi there

    I have created an excel worksheet template with a data table (4 columns) and a couple of buttons ($, %, Unit) to change the number formatting of columns 2-4 within that datatable. This works fine within the template.

    The workbook is set up a menu of buttons to call upon different worksheet templates and this then makes a copy of the template to work with.

    Now, once the above template worksheet has been copied and renamed, I can then decide whether the data entered in that table should be $, % or unit by pressing the appropriate buttons (which were created on the original template).

    However, once the table worksheet has been copied, it seems that the table reference name has also change, so all of a sudden the buttons no longer work.

    Code used:

    Please Login or Register  to view this content.
    Table3825 is the table name in the template, but the table in the new copy is now 38255! How would I be able to fix this as all future copies will have different table names? (NB the cell formatting of the first column in the table should always remain the same and should not be affected by the format change on subsequent columns)

    Thank you!
    Last edited by Vegiepie2016; 02-24-2016 at 06:06 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: VBA Table reference if working with a copy of the table

    Please use Code Tags in your code excerpts to comply with Forum rules.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: VBA Table reference if working with a copy of the table

    Perfect - that definitely did the trick!

    Many thanks...

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: VBA Table reference if working with a copy of the table

    You're welcome. And thanks for adding the Code Tags

  5. #5
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: VBA Table reference if working with a copy of the table

    Ok - I came across another problem. In the above example, [[Measure1]:[Measure 3]] (effectively columns F - H of the table - these are the table column headers) can be renamed by the user. When they do however, the formula doesn't work any more.

    Is there any way to reference named ranges if these aren't fixed names?

  6. #6
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: VBA Table reference if working with a copy of the table

    Please Login or Register  to view this content.
    If they add or remove columns, you will have another different problem.

  7. #7
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: VBA Table reference if working with a copy of the table

    Well, great you mentioned it as it is an expandable table (rows and columns with initial 3 - 4 rows depending on table).

    The main thing is that the values in columns A to E (A-D non-table info, E will become chart X Axis), have to remain untouched, the following columns (F onwards ) have to be changed according to the button click.

    Would it work if the .Resize is removed from your code? (Don't have access to my workbook at present...)

    Thanks again...

  8. #8
    Valued Forum Contributor
    Join Date
    05-14-2012
    Location
    Unknown
    MS-Off Ver
    Unseen
    Posts
    429

    Re: VBA Table reference if working with a copy of the table

    I'm sorry, it's impossible to anticipate and cater for all the changes that you anticipate that your users can/will make.

    The initial problem was "how to cater for a changing Table name, resulting from copying the Table. Done ... original question asked and answered.

    Your original code used Table Headers ... which can, apparently, be changed. Code for this rider has been provided ... use Offset and Resize relative to the Data area to refer to the columns whose headers may change. Question asked and answered.

    Now you're saying that they can add and delete columns. Is there anything static to which you can pin this code?

    If you're going to allow them to change the headers AND add, delete and shuffle them, I can't see how you're going to do it.

    The only thought/suggestion is that you have a hidden row above your table and, in that, you have some static "Table headers". You could then use this to match your "expected" column headers with the columns, even though they may have moved. Assuming that columns may be deleted, you'd need to have error handling to cater for missing columns. You will have to handle the columns independently given that some of them may have gone missing.

  9. #9
    Registered User
    Join Date
    01-28-2016
    Location
    Western Austalia
    MS-Off Ver
    2010
    Posts
    36

    Re: VBA Table reference if working with a copy of the table

    Mmm, thought I might be pushing my luck. Simple project with more and more demands! Thanks for the help so far...

+ 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: 0
    Last Post: 09-30-2015, 04:50 PM
  2. Copy and paste not working in dynamic table range!
    By dhcwong in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-04-2015, 01:33 AM
  3. Replies: 2
    Last Post: 08-27-2014, 03:13 PM
  4. [SOLVED] fill reference table based on data available in master Table
    By jsimha in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-31-2013, 12:19 PM
  5. Reference / retrieve data from a table and populate a table in a different workbook?
    By philuptuous in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-17-2012, 06:21 AM
  6. using a dynamic reference cell to copy a range of cells within a data table
    By mcash in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2010, 10:22 AM
  7. VBA Code for a pivot table to open database and to reference table current page
    By Pete Straman Straman via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-21-2005, 12:06 AM

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