+ Reply to Thread
Results 1 to 4 of 4

Search for multiple matching cells and copy/paste range?

Hybrid View

  1. #1
    Registered User
    Join Date
    04-01-2014
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2011 Mac, 2013 PC
    Posts
    2

    Search for multiple matching cells and copy/paste range?

    Hi there,

    I have a very large spreadsheet (>500000 rows) and need to consolidate the data between the sheets. Can someone please assist me in creating a macro that would search for a row in 1 sheet that has the exact same values for two columns (in the same row) in another sheet?

    I have tried to simplify my spreadsheet and have attached a file that includes only 10 rows of data.

    Basically, in the sheet "sche", I need to search columns A and B for a row that exactly matches the values in a row in sheet "act", columns D, and E, respectively. If there is a match, I need to copy the range "C:AO" of the matched row from "sche" and paste into F of "act".

    Using some answers I found on Mr.Excel and Yahoo Answers, I have drafted a novice code - but obviously, I cannot get it to run.

    I also don't know how to declare my variables.
    Values in columns A ("sche") and D ("act") are integers.
    However, values in column B ("sche") and E ("act") are dates in the format YYYY-MM-DD.

    Sub Consolidate_Data()
        
        Dim i, j, LRSche, LRAct
        
        LRSche = Sheets("sche").Range("A" & Rows.Count).End(xlUp).Row
        LRAct = Sheets("act").Range("D" & Rows.Count).End(xlUp).Row
        
        For i = 1 To LRSche
        For j = 1 To LRAct
        
        If Sheets("sche").Cells(i, "A").Value = Sheets("act").Cells(j, "D") Then
        If Sheets("sche").Cells(i, "B").Value = Sheets("act").Cells(j, "E") Then
        Sheets("sche").Cells(i, "C").Resize(, 38).Copy
        Sheets("act").Cells(j, "F").Paste
        
        End If
        End If
        Next i
        Next j
        
    End Sub
    I appreciate any help I can get and thank you very much in advance!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Search for multiple matching cells and copy/paste range?

    Hi,

    Try this macro...
    Attached Files Attached Files
    Regards,
    Rudi

  3. #3
    Registered User
    Join Date
    04-01-2014
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2011 Mac, 2013 PC
    Posts
    2

    Re: Search for multiple matching cells and copy/paste range?

    Quote Originally Posted by RudiS View Post
    Hi,

    Try this macro...
    Hi Rudi, this works perfectly! Thank you so much! I'm in the (very early) process of learning vba/macros and really appreciate your assistance.

  4. #4
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Search for multiple matching cells and copy/paste range?

    Great to hear...

+ 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. Replies: 3
    Last Post: 11-26-2013, 04:53 AM
  2. Replies: 1
    Last Post: 11-25-2013, 09:30 AM
  3. Copy/Paste range of cells to another worksheet based on matching criteria
    By maa50904 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-05-2013, 12:07 AM
  4. Replies: 1
    Last Post: 01-17-2013, 05:27 PM
  5. [SOLVED] Search workbook for matching detail and copy/paste the row/column content.
    By GB.RTMC in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-28-2012, 09:55 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