+ Reply to Thread
Results 1 to 6 of 6

Select column from table using variable table name -- VBA

  1. #1
    Registered User
    Join Date
    10-01-2009
    Location
    Durham, NC
    MS-Off Ver
    Excel 2007
    Posts
    14

    Select column from table using variable table name -- VBA

    Hello. I am trying to select various table columns or cells for editing using VBA. In my script, the user enters a department name and the month. These variables are then combined to create the variable tableName. The script then selects the appropriate data, creates a table, and names it tableName. So far so good.

    Next, I want to be able to select columns to enter formulas and formatting. For example, I tried using this code to calculate a percentage column:
    Please Login or Register  to view this content.
    but I get a "Type mismatch" error.

    Elsewhere, I want to select a few columns and format them. My selection statement reads:
    Please Login or Register  to view this content.
    but again, it doesn't work.

    Would using ListObjects terminology help?

    Thanks a lot,
    JJ
    Last edited by jscott15; 09-08-2010 at 10:03 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Select column from table using variable table name -- VBA

    You need to use quotes not square brackets when concatenating the table name and columns:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  3. #3
    Registered User
    Join Date
    10-01-2009
    Location
    Durham, NC
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Select column from table using variable table name -- VBA

    Thank you for this help. I was able to get it working, as in the following example:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-07-2012
    Location
    Here, here
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Select column from table using variable table name -- VBA

    Im having issues getting this to work:
    Where a(1) = a column name

    ActiveSheet.Range("Table1[[#Headers],[" & a(1) & "]]")

    I get a application-defined or object-defined error message
    When I use a non-variable it works (actually type something in there)
    How do I use a variable?

  5. #5
    Registered User
    Join Date
    08-07-2012
    Location
    Here, here
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Select column from table using variable table name -- VBA

    Nevermind. Typo'd the variable. Sigh, monday detail.

  6. #6
    Registered User
    Join Date
    01-02-2016
    Location
    Cracow, Poland
    MS-Off Ver
    2013
    Posts
    1

    Re: Select column from table using variable table name -- VBA

    My mistake, please delete post.
    Last edited by kkris77; 01-03-2016 at 06:33 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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