+ Reply to Thread
Results 1 to 3 of 3

Search for code in another worksheet and copy information back

  1. #1
    Registered User
    Join Date
    05-12-2016
    Location
    NZ
    MS-Off Ver
    Office 14
    Posts
    41

    Search for code in another worksheet and copy information back

    Hi there,

    I've got a spreadsheet (Workbook 1) which contains product information across a number of columns, each row being a unique product with a unique product code attached. Separately, there is another spreadsheet (Workbook 2) with sales data for each month which references each product sold by the same unique product code. The unique product code is in column A in Workbook 1, and column N in Workbook 2. All information required is on Sheet 1 of each workbook.

    I need a macro to, for each row of Workbook 2, search for the product code in Workbook 1 and then copy some information from the relevant rows back to Workbook 2.

    e.g. if workbook 1 looks like this:
    Col A Col C Col G
    A1 blue w
    A2 black x
    A3 yellow y
    A4 green z

    And workbook 2 looks like this:
    Col A Col B
    12 A1
    3 A3
    56 A4
    2 A2

    I need Workbook 2 to come out like:

    Col A Col B Col N Col O
    12 A1 blue w
    3 A3 yellow y
    56 A4 green z
    2 A2 black x

    Note that the cells being copied from Workbook 1 might not be next to each other (e.g. Col C and Col G) but the place they will be copied to in Workbook 2 would be (e.g. Col N, Col O). Both sets of columns are at set places that will never change.
    Also, they are different workbooks, saved in different places. I don't mind having to open Workbook 1 before running the process, but I can't copy the information from Workbook 1 onto a sheet in Workbook 2 for security reasons.

    I'm competent with macros within one workbook, but I have difficulty working with other workbooks. Below is the structure of how I would expect it to run, the two lines that are commented out are the lines that aren't real code because I don't know how to write it.

    Please Login or Register  to view this content.

    Can anyone help with the commented out lines? Or give me guidance for how to work with other workbooks in this way?


    Thanks,
    Pango

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Search for code in another worksheet and copy information back

    This is not tested, but it should get you pointed in the right direction.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    05-12-2016
    Location
    NZ
    MS-Off Ver
    Office 14
    Posts
    41

    Re: Search for code in another worksheet and copy information back

    Thank you so much AlphaFrog, I see how the code would work now - I haven't been able to test it yet but I'll post here when I have

+ 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] Help VBA Search Copy and paste information
    By richlilrich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2016, 11:39 PM
  2. Userform that updates worksheet and reads information back
    By bevc in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2016, 07:05 AM
  3. Copy Worksheet from one Worbook to another without copying back links
    By Warbe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-11-2015, 12:43 PM
  4. Replies: 2
    Last Post: 03-17-2014, 04:19 PM
  5. Macro to search and copy specific information on the next blank line.
    By jlo33 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-26-2013, 01:58 PM
  6. search 2 different columns for same information and copy entire row
    By Biogeek1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 08:44 AM
  7. Search or Find to False in a row/back to back
    By zit1343 in forum Excel General
    Replies: 2
    Last Post: 04-20-2012, 04:35 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