+ Reply to Thread
Results 1 to 10 of 10

VBA to import selective columns from a different sheet

  1. #1
    Registered User
    Join Date
    01-12-2020
    Location
    California
    MS-Off Ver
    2016
    Posts
    53

    Unhappy VBA to import selective columns from a different sheet

    Hello All,

    I have 2 files in the same folder: source and destination files. The source files contains more columns than the destination files.
    I need to import only selective columns from source to the destination where columns and all their contents will be placed in a different order. The order of columns in the source changes frequently; therefore I need to be able to import the columns based on searching the header than indicating a certain column number position in the destination. I want to write a VBA that would be triggered from the destination file without the source file opened.
    Your bright minded people help would be highly appreciated.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA to import selective columns from a different sheet

    Only if
    1) Header names are all IDENTICAL.
    2) Sheet name in Source file is FIXED. "EDRSScheduling"
    The code needs to be in a new workbook or any workbook other than 2 workbooks in question.
    Please Login or Register  to view this content.
    Last edited by jindon; 10-16-2020 at 01:05 AM.

  3. #3
    Registered User
    Join Date
    01-12-2020
    Location
    California
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA to import selective columns from a different sheet

    Thanks Jindon; but I am getting error in line 13:
    myHeading = "`" & Join(.Parent.Evaluate(.Rows(1).Address & "&"""""), "`, `") & "`"
    The code has to be in the destination file and import silently from the source file within the same folder without opening it.
    Also I don't see in your code, where would I be able to specify where specific columns from the code based on column header names would land in the destination - this is a requirement of my project.
    Perhaps you can kindly clarify and help? Thank you so much!

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA to import selective columns from a different sheet

    Quote Originally Posted by aldenes View Post
    The code has to be in the destination file and import silently from the source file within the same folder without opening it.
    I thought you would run the code from other workbook.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA to import selective columns from a different sheet

    Thanks for the PM and rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  6. #6
    Registered User
    Join Date
    01-12-2020
    Location
    California
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA to import selective columns from a different sheet

    Jindon,

    This is awesome and takes care of 99% of my problem; there's one more tweak needed, hope it's possible and not too much to ask; if the destination contains more columns than in the source I just need to leave those blank; that's important as I import only selective columns into a larger spreadsheet; please used attached as an example for destination file. I apologize not to have included this in the original problem description as I just realized.
    Thank you so much!

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA to import selective columns from a different sheet

    Try change to
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-12-2020
    Location
    California
    MS-Off Ver
    2016
    Posts
    53

    Re: VBA to import selective columns from a different sheet

    Awesome. Thank you very much!!

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: VBA to import selective columns from a different sheet

    You are welcome.

  10. #10
    Registered User
    Join Date
    11-29-2021
    Location
    Canada
    MS-Off Ver
    office 360
    Posts
    1

    Re: VBA to import selective columns from a different sheet

    Hi,

    I have a similar question. Sorry I am very new to VBA. Like just born stage. I have a sheet which has different headings with col. That sheet is dynamic. I want to have selective data trasnfered to a different sheet. Is it possible to use the above code or can someone give me something generic? In which I can make changes to the headings myself?

+ 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] Import selected columns from sheet to sheet help
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2015, 09:37 PM
  2. Merge columns,sheet (Import script)
    By elmnas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-16-2015, 12:21 PM
  3. Replies: 0
    Last Post: 06-17-2013, 05:33 AM
  4. Replies: 1
    Last Post: 02-13-2013, 01:32 PM
  5. Replies: 5
    Last Post: 12-11-2012, 05:04 AM
  6. Selective columns
    By Marvo in forum Excel General
    Replies: 143
    Last Post: 08-14-2011, 01:42 PM
  7. Import selective data in Excel2007
    By Rosyfred in forum Excel General
    Replies: 0
    Last Post: 02-20-2009, 04:20 AM

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