+ Reply to Thread
Results 1 to 6 of 6

comparing and copying multiple rows on 2 sheets

  1. #1
    Registered User
    Join Date
    01-18-2007
    Posts
    3

    comparing and copying multiple rows on 2 sheets

    I have been looking on here but I am still not understanding how to write the code. I have the concept but i don't know excel VBA enough.
    Heres the problem.
    MO view 'sheet 1
    A G
    M405250
    M406230
    M408250
    M413480
    M413690
    M414260
    M414280

    RM 'sheet 2
    A C
    M405040 12/1/06
    M405250 12/5/06
    M406230 12/11/06
    M408250 12/11/06
    M413480 12/15/06
    M413690 12/15/06
    M414210 12/18/06
    M414210 12/18/06
    M414230 12/19/06


    I need to compare Column A on both sheets and if they match copy column C on the corisponding line in "RM"sheet to Column G on "MO view"sheet. If there is no match it needs to be left blank. I would also like it to stop when it gets to the last line with data in "MO view"
    Results would look like
    MO view
    A G
    M405250 12/5/06
    M406230 12/11/06
    M408250 12/11/06
    M413480 12/15/06
    M413690 12/15/06
    M414260
    M414280

    I am not sure how to do this and make sure it looks all the way through "RM" and returns a date or blank for each one.

    Any code would be much appriciated.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    This should do the trick

    Sub Test()
    Sheets("MO View").Activate
    For N = 1 To Cells(65536, 1).End(xlUp).Row
    If Application.CountIf(Sheets("RM").Columns(1), Cells(N, 1)) > 0 Then
    Cells(N, 7) = Sheets("RM").Columns(1).Find(Cells(N, 1), , xlValues, xlWhole).Offset(0, 2)
    End If
    Next N
    End Sub
    Martin

  3. #3
    Registered User
    Join Date
    01-18-2007
    Posts
    3

    Keeps repeating

    Thanks that works but now it keeps restarting after it reaches the last line that has data. How do i make it stop?

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    Hmmmm... Didn't do that for me.


    Have you put the code onto a module or onto the the tabs for one of the sheets. I sounds like you have somehow got it linked to a worksheet change event. Try creating a new module and putting it there.

    Does this help?

  5. #5
    Registered User
    Join Date
    01-18-2007
    Posts
    3
    That works perfect you just saved me an hour a day when I now can complete the task once at the end of the month. Thank you.

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    Glad to help

    I hope that you enjoy the spare hour!

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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