+ Reply to Thread
Results 1 to 8 of 8

Searching one sheet and copying row to another sheet

  1. #1
    Registered User
    Join Date
    05-25-2011
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Searching one sheet and copying row to another sheet

    forumtest.xlsx
    If you can figure out how to do this with formulas I'll be fully satisfied. I can't though.

    I have a workbook with two sheets. Sheet1 contains a set of information about orders. Sheet2 has a different set of info about orders. What I'm looking to do is run a macro that will check to see if the order numbers are the same and if they are copy the data from Sheet1 and put it in the same row but next to the line that has the same order in Sheet2.

    Sheet1 has the order numbers in column E whereas Sheet2 has the order numbers in column B. An additional complication is that the order numbers in the sheets are different formats. They are 123456 in Sheet1 but might be AA123456 or B123456 or 123456 in Sheet2.

    My current thoughts were running a loop, for every row in Sheet1, setting the value of Erow to ordernumber, copying the row, moving to Sheet2, searching for ordernumber. If it's found, paste the values starting in column O of Sheet2 in the same row the value is found. But I can't make that work. I also don't know if there is an easier way to do this. Any ideas? Thanks
    Last edited by gryffin13; 07-13-2012 at 09:53 AM. Reason: Corrected thread title to topic only

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Searching one sheet and copying row to another sheet

    You should be able to do this with just formulas, VBA may not be necessary.

    To be certain, click GO ADVANCED and use the paperclip icon to post up a sample copy of your workbook. Make sure the workbook demonstrates your desired results if possible, or just highlight the cells you're trying to fix. Use two versions of sheet2, BEFORE/AFTER sheets, if that helps make it clearer. There just needs to be enough data in the sample to clearly demonstrate to us the variations that must be dealt with.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-25-2011
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Searching one sheet and copying row to another sheet

    Alright, I added an example. I assume you are correct, but I'm not smart enough to figure it out either way

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Searching one sheet and copying row to another sheet

    You used the word "random data" in every cell making it essentially useless. Even the titles?
    This will make is much harder for you to see the results actually working.

    Here's your sheet back with actual randomized data. Now mockup sheet2 the way it would appear based on that, show the answers you expect.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-25-2011
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Searching one sheet and copying row to another sheet

    I was worried that might make things difficult. Sorry. Hopefully this might clarify

    forumtest2.xlsx

    Thanks for the help.

  6. #6
    Registered User
    Join Date
    05-25-2011
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Searching one sheet and copying row to another sheet

    I know you are working on it from a formula POV, but I'm still going to show you what I'm working on with VBA. I feel like it should be simple. If you happen to know what the issue is, would you mind taking a look? If not for anything else than for my curiosity.

    Please Login or Register  to view this content.
    the issue I think is right here:
    Selection.Find(What:=ordernumber <=====

    I don't know if there is a syntax that I am missing if I want to include a variable there. Or maybe I am using the wrong variable type?

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Searching one sheet and copying row to another sheet

    Put this formula in R5:

    =REPLACE(B5,1,MIN(SEARCH({0;1;2;3;4;5;6;7;8;9},B5&1234567890))-1,"")+0

    Put this formula in S5 and copy across:
    =IFERROR(INDEX(Data!A:A, MATCH($R5, Data!$E:$E, 0)), "")

    Format the various cells on row 5 the way you need.

    Now just copy R5:AE5 down.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Searching one sheet and copying row to another sheet

    Here's the VBA method:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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