+ Reply to Thread
Results 1 to 7 of 7

Load worksheet to array, load new worksheet with specific parts of array

  1. #1
    Registered User
    Join Date
    12-14-2011
    Location
    Rochester, MN, USA
    MS-Off Ver
    Office 2010 and 365
    Posts
    54

    Question Load worksheet to array, load new worksheet with specific parts of array

    I am looking for the most simple and/or effective way to load an entire worksheet into an array, and then selectively put data (by column) into a different workbook.
    For example; lets say I have a worksheet with 15 columns and is X rows long. I put that data into an array. Now I only want to put the columns that I want into a new workbook - columns where the header = "Something Here".

    I would load the array like this:
    Please Login or Register  to view this content.
    I know that I could loop through the array and do a Select Case to find the headers I want, like below, but that seems like it's more than it should be.
    Please Login or Register  to view this content.
    What I am looking for is something a lot more compact and simple... IF it's possible?
    Please Login or Register  to view this content.
    I'm assuming "Name" would have to be replace with some sort of FIND or SEARCH function.

  2. #2
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Load worksheet to array, load new worksheet with specific parts of array

    It's pretty easy. If you place an example file. With Application.Index you can adjust the column order.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    12-14-2011
    Location
    Rochester, MN, USA
    MS-Off Ver
    Office 2010 and 365
    Posts
    54

    Re: Load worksheet to array, load new worksheet with specific parts of array

    Quote Originally Posted by Vraag en antwoord View Post
    It's pretty easy. If you place an example file. With Application.Index you can adjust the column order.
    Please Login or Register  to view this content.
    @Vraag But that does not seem to do anything that I'm asking for. I don't know where each column is at in the SOURCE file, therefore I can't do any reordering or "copy/paste" by static numbers. I need to be able to "search" the array header to find the correct column index.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,070

    Re: Load worksheet to array, load new worksheet with specific parts of array

    You could use something like
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-14-2011
    Location
    Rochester, MN, USA
    MS-Off Ver
    Office 2010 and 365
    Posts
    54

    Re: Load worksheet to array, load new worksheet with specific parts of array

    Quote Originally Posted by Fluff13 View Post
    You could use something like
    Please Login or Register  to view this content.
    @Fluff13 That gets me a little closer - I see what you are doing is really just building a second array (ColAry) from the first (arrCopy) and then "pasting" it on the worksheet. That is great, as long as I have only a few columns, but what if I have to do a SELECT CASE for 5, 10, 15... column names?

    Sure, I could also predetermine the column numbers using something like
    Please Login or Register  to view this content.
    but again that means I have to have X number of lines just to find each header index.

    Is there no way to do a FIND or SEARCH in an array without iteration? I guess I'm just trying to figure out the fewest lines of code for this.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,070

    Re: Load worksheet to array, load new worksheet with specific parts of array

    I would tend to stick with the Select Case, that way you only loop through the array once & will probably be the quickest way of doing it.

  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: Load worksheet to array, load new worksheet with specific parts of array

    Use another array for the headings.
    If posting code please use code tags, see here.

+ 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. load data into array if condition is met
    By esbencito in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-23-2019, 11:08 PM
  2. Easiest way to load data from a csv into an array
    By jlt199 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2018, 11:02 AM
  3. Load selected cells into an array
    By Anil K Goel in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-23-2017, 11:59 AM
  4. 2d array sort and load to list box
    By SPARKY347 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-08-2016, 11:12 AM
  5. Load Values To Array Using .CurrentRegion With Array Base 0
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2016, 07:53 AM
  6. Load an array from ADO recorset
    By cgkmal in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 07-18-2014, 04:07 PM
  7. Load Contents of array into Range
    By additude in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-26-2008, 07:01 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