+ Reply to Thread
Results 1 to 3 of 3

VBA -How to keep existing range column headers when converting to table

  1. #1
    Registered User
    Join Date
    05-20-2014
    Location
    Salt Lake City, Utah
    MS-Off Ver
    2013
    Posts
    31

    Question VBA -How to keep existing range column headers when converting to table

    Please Login or Register  to view this content.
    That's my [found on internet forum] code for turning an existing range into a formatted table. Row 2 has headers, but running this code strips them out and inserts the default "Column 1", "Column 2", etc.
    I'm new enough to VBA to know there's a simple fix, but haven't found it yet. Help?

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA -How to keep existing range column headers when converting to table

    Hi Quinn.Farley,

    Your error is caused by a typo.
    Your x1Yes should be xlYes. You have a one instead of a lower case L.

    In their not so infinite wisdom, the Microsoft people should have avoided the lower case L.

    Your error is also caused by the lack of 'Option Explicit', which would have caught the error as a compile error.


    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Lewis

  3. #3
    Registered User
    Join Date
    05-20-2014
    Location
    Salt Lake City, Utah
    MS-Off Ver
    2013
    Posts
    31

    Re: VBA -How to keep existing range column headers when converting to table

    That was it! Thank you very much for your help, LJ Metzger. Works perfectly now. I don't have a good grasp about "option explicit", but will research and learn it now.

+ 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: Fill out column with lookup table refering to table headers
    By AnnaGT in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-02-2015, 03:03 AM
  2. How do I use column headers from a table in SUMIFS?
    By cmcgath in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-23-2014, 11:52 AM
  3. Help required in Converting Multiple Rows to Columns and add Column Headers
    By Swaroopa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-08-2013, 07:39 AM
  4. Help required in Converting Rows to Columns and add Column Headers
    By Swaroopa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2013, 07:15 AM
  5. populate a table using row and column headers
    By garywilson4 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-05-2012, 10:43 AM
  6. Help with Converting Multiple Rows to Columns and add Column Headers
    By Lmsloman in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-27-2010, 10:45 AM
  7. Loop through column headers to search from column name and get cell range
    By Pie in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-28-2005, 08:20 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