+ Reply to Thread
Results 1 to 8 of 8

VBA copy specified columns from one sheet to another using array

  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    VBA copy specified columns from one sheet to another using array

    Hi,

    Looking for ideas, to copy specific named columns from a source sheet to another sheet created in the same workbook.
    Due to the length of the column headers, and the sheer amounts of them in the source files, I'm hitting into the limits of what a single Array("Column_1", "Column_4","Column_6"...) can contain.

    For the sake of this post lets say I need 150 columns scattered throughout of 300 in my source.
    The exact amount of columns in the source sheet as well as their order can vary. Which is why I need somewhere to list the specific header rows that I need and then run through and copy only those to a Destination sheet.

    Previously I've the below code to copy columns between/to sheets but it doesn't work with the amount of them in this case.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Tunesmith; 01-31-2019 at 12:03 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: VBA copy specified columns from one sheet to another using array

    Why not just list the columns in a hidden worksheet and process that rather than an array?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: VBA copy specified columns from one sheet to another using array

    Try it like
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    Re: VBA copy specified columns from one sheet to another using array

    Quote Originally Posted by TMS View Post
    Why not just list the columns in a hidden worksheet and process that rather than an array?
    Hadn't considered that, would that be listing the column in a table and using that as "the array" so to speak?
    Say I have the list of columns in "Workbook_B" how would I write that? I'm interested in this as an alternative.

    Quote Originally Posted by Fluff13 View Post
    Try it like
    Please Login or Register  to view this content.
    Thank you for this, it looks like a more efficient way of writing the array. The resulting array is a massive 5300 characters long but it works.

    I'm interested in the alternative proposed by TMS as well, before marking as solved.

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

    Re: VBA copy specified columns from one sheet to another using array

    With a list of the columns you wanted in A2 downwards on a sheet called "List", you could use
    Please Login or Register  to view this content.
    Last edited by Fluff13; 01-31-2019 at 10:12 AM.

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

    Re: VBA copy specified columns from one sheet to another using array

    You will also ned to tweak the loop through the array
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    08-02-2012
    Location
    Europe
    MS-Off Ver
    Excel 2013/365
    Posts
    24

    Re: VBA copy specified columns from one sheet to another using array

    Quote Originally Posted by Fluff13 View Post
    You will also ned to tweak the loop through the array
    Thank you!

    I modified the code slightly to use a named table in my addin workbook that's loaded alongside the disposable files.
    Code below for reference:

    Please Login or Register  to view this content.

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

    Re: VBA copy specified columns from one sheet to another using array

    Glad you got it working & thanks for the feedback.

    @TMS
    Thanks for the Rep & happy to help.

+ 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] How can I array three columns from one sheet into another?
    By 27POP27 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 11-14-2018, 08:17 AM
  2. copy from sheet to array
    By twozedz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2016, 06:57 AM
  3. How to copy an array to excel sheet?
    By helpmeimlost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2014, 02:24 AM
  4. [SOLVED] Copy columns from one sheet to next empty columns in another sheet
    By GavJ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-10-2013, 07:08 PM
  5. Macro to copy 3 columns of data from multiple sheets into 3 columns on 1 sheet
    By bballdcm2007 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-15-2012, 04:37 PM
  6. Copy value to Array variables use them in another sheet!
    By ravikiran in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2012, 04:15 AM
  7. Copy from one sheet using an array
    By peakymatt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2009, 09:23 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