+ Reply to Thread
Results 1 to 8 of 8

Macro to create a table of an unknown size of data

  1. #1
    Registered User
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Macro to create a table of an unknown size of data

    I'm trying to create a table of data in an excel file. The file already exists with headings from A-N but the number of rows could be anything. How can I create a table in VBA that will make a table out of data with no set range?

  2. #2
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Macro to create a table of an unknown size of data

    Hello mtma,

    Your question is very broad. An example would help. If you just want a general answer, here is a way to grab all data from a sheet into an array:
    Please Login or Register  to view this content.
    1. Include a sample workbook with an example of the result you want
    2. Use [CODE] and [FORMULA] wrappers for your VBA code or excel formulas
    3. If your question has been answered, mark the thread as SOLVED and click on the "Add Rep" star to thank whoever helped you.

  3. #3
    Registered User
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Macro to create a table of an unknown size of data

    I'm not sure how better to explain it. I have an array of data (n x 18) in an excel sheet and I want to make a macro that will create a table from that data.

  4. #4
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Macro to create a table of an unknown size of data

    What do you mean by "table"? Isn't it already a table? Do you want a pivot table? Do you want an array?

  5. #5
    Registered User
    Join Date
    07-30-2014
    Location
    USA
    MS-Off Ver
    2010
    Posts
    36

    Re: Macro to create a table of an unknown size of data

    It is currently just data in a cell but I want it to be formatted as a table

  6. #6
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Macro to create a table of an unknown size of data

    Sorry, you're going to have to provide a sample for me to understand. To me, data in cells and table are the same thing, unless you're trying to do a text-to-columns split. I can't tell if you want to summarize the data, parse it, store it in memory, or just format it. An example workbook would make things more clear.

  7. #7
    Registered User
    Join Date
    01-12-2014
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Macro to create a table of an unknown size of data

    Hi mtma. Did you ever find a solution to your question? I think I have the self-same requirement, ie find a VBA means of doing the same as selecting a single cell in a block of data, and using Insert/Table. At this point Excel identifies all the contiguous data and, if you OK, it creates the new table based on that range. With the VBA solution, I need to be able to run the code on a block of data that could be any number of rows deep and have it automatically set the correct range from which to create the table object. Hope I've described it clearly!

    P

  8. #8
    Registered User
    Join Date
    01-12-2014
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Macro to create a table of an unknown size of data

    ... and I just answered my own question:

    Sub ctable()


    ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1").CurrentRegion, , xlYes).Name = "Tbl001"

    End Sub

    This assumes that the range includes cell A1; if not, substitute any cell within the block and CurrentRegion will pick up the correct range. Hope this helps.

    P

+ 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. [SOLVED] Macro to add rows depending on the size of data volume and create new workbook
    By bimmy80 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-16-2015, 11:05 AM
  2. Replies: 3
    Last Post: 04-22-2012, 09:35 PM
  3. Create a Table That Can Expand in Size
    By doraen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2011, 09:11 PM
  4. How to access last row of unknown data size?
    By aero23 in forum Excel General
    Replies: 5
    Last Post: 04-20-2009, 09:51 PM
  5. Replies: 3
    Last Post: 04-15-2009, 11:50 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