+ Reply to Thread
Results 1 to 9 of 9

Copy, Search, Then Paste Needed

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2009
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2003
    Posts
    29

    Copy, Search, Then Paste Needed

    Newbie! I am looking for a macro to assign to a command button that will copy cells in row A2:A10 in worksheet1 based on a criteria (date) giving in cell A1 , then search worksheet2 (column A) for the criteria (date) giving in (Worksheet1! A1) and paste the cells in (Worksheet1! A2:A10) next to the found date in worksheet2.

    I would really appreciate the help.
    Last edited by strato1983; 03-27-2009 at 02:27 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Copy, Search, Then Paste Needed

    I suggest you attach a small sample workbook illustrating your data and desired results.

  3. #3
    Registered User
    Join Date
    03-24-2009
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Copy, Search, Then Paste Needed

    Thanks for the fast response!
    Here's a sample. Basically what I need,

    Using a command button
    Copy cells B1:E1 then paste the values to sheet2 next to the date based on cell A1 in sheet1.

    If you change the (criteria) date in A1 than click the command button cells B1:E1 will be copied next to that date, and so on.
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Copy, Search, Then Paste Needed

    OK, that's easily done, but why couldn't you just use the VLOOKUP formula?

    Where are the values in B1:E1 coming from when you change the date?

  5. #5
    Registered User
    Join Date
    03-24-2009
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2003
    Posts
    29

    Re: Copy, Search, Then Paste Needed

    Sounds like you know your stuff StephenR

    I want the user to ensure that the data in sheet1 is correct before copying the values to sheet2. A command button adds a user step but gives the added security. If that makes any sense.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Copy, Search, Then Paste Needed

    Sort of, though you could just use data validation. Anyway, try assigning this to a button:
    Sub x()
    
    Dim rDates As Range, r As Long
    
    With Sheet2
        Set rDates = .Range("A1", .Range("A1").End(xlDown))
        On Error GoTo errline
        r = WorksheetFunction.Match(Range("A1"), rDates, 0)
        On Error Resume Next
        .Cells(r, 2).Resize(, 4).Value = Range("B1:E1").Value
    End With
    
    Exit Sub
    
    errline: MsgBox Range("A1") & " not found"
    
    End Sub

+ 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