+ Reply to Thread
Results 1 to 11 of 11

Copy data in columns E:G to different workbook with worksheet = value in column C

  1. #1
    Registered User
    Join Date
    09-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Copy data in columns E:G to different workbook with worksheet = value in column C

    Hello,
    I am new to VBA. I have a master spreadsheet that has data populated in columns A to G. I would like a macro to loop through the data in columns E:G copying the data in each row to another workbook called Vendors.xlsx that contains a worksheet with the same name as the value in column C. The data should be pasted special values in the first empty cell starting in B3.

    For example. From the below data, the data in row 2, columns E, F and G, would be copied and pasted into workbook Vendors.xlsx, worksheet Vendor1. Data in row 3 would be pasted into the worksheet Vendor2.

    Thank you in advance for any assistance.

    Column C Column D Column E Column F Column G
    Vendor # Location Address City State
    Vendor1 1 Main St Philadelphia PA
    Vendor2 3 XYX St New York NY
    Vendor3 1 ABX Rd Seattle WA
    Vendor2 1 G St Trenton NJ
    Vendor4 3 Race St Philadelphia PA
    Vendor1 2 1st St New York NY

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,791

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    this worked for me. Try it out and advise

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Hi Luff

    This works as well. I've set it to copy from Sheet1 to the right Vendor sheet. Change if it's not right
    I've attached a sample file
    Let me know if it's no good

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

  4. #4
    Registered User
    Join Date
    09-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Thanks Philb1.

    It works good expect for two issues. 1. The vendors have multiple locations. If I add additional rows for the same vendor, when the macro runs, it appears to be writing over the first location. Can you adjust the code so it pastes "special" in the next blank row? 2. If I add a header above the vendors, the macro runs to error because the header text is not a worksheet in the vendors.xlsx file. On the attached spreadsheet, I have hightlight the cells in yellow were the header would be.
    Thanks Luffk73
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Thanks for looking at this alansidman. I have close to 50 vendors so I don't want to have to manually type all the vendors into the code.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,791

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Try changing this line in Philb1's code

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Alan

  7. #7
    Registered User
    Join Date
    09-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Hi Alan,

    That is move the row the data is being pasted in down 1 row but still only 1 row of data is appearing.

    Luffk73

  8. #8
    Registered User
    Join Date
    09-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Hi Alan,

    The code is also using the "paste" function, not the "Paste Special - Values" function. Can that be changed?

    Thanks,

    Luffk73

  9. #9
    Registered User
    Join Date
    09-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Hi Alan,

    I was able to get it to work by changing


    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    how can I change this line to paste special?

    Please Login or Register  to view this content.
    Thanks

    Luffk73

  10. #10
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    In my defense I was almost asleep when I posted last night
    Here's Version 2 & hopefully works as you would like

    Please Login or Register  to view this content.
    V2 is attached for you to play with
    Have fun
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    09-23-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copy data in columns E:G to different workbook with worksheet = value in column C

    Thanks Alan!!!

+ 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] copy from another workbook's worksheet based on column name.
    By Jhail83 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-01-2013, 11:30 AM
  2. Copy a row if an X is in a column to a worksheet in a workbook
    By Bazmama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2013, 04:20 AM
  3. Replies: 6
    Last Post: 09-27-2011, 02:11 PM
  4. Replies: 1
    Last Post: 04-01-2006, 03:50 PM
  5. Replies: 3
    Last Post: 01-15-2005, 11:06 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