+ Reply to Thread
Results 1 to 3 of 3

Copying a row based on matching unique values

  1. #1
    Registered User
    Join Date
    03-12-2008
    Posts
    36

    Copying a row based on matching unique values

    Hi,

    I have the following code which takes a unique value from 'sheet 1', and searches for the value in 'sheet 2'. If there is a matching value in sheet 2 it will copy the full row into sheet three.

    I need to extend the code so that all values from 'sheet 1' are copied to 'sheet 3' even if there is no matching value in 'sheet 2'. If there is a matching value in 'sheet 2' however I need the entire row to be copied to 'sheet 3'

    See the code I have at the moment.

    Sub moving()
    Dim c As Range, d As Range
    Worksheets("Sheet2").Activate
    For Each d In Worksheets("Sheet1").Range("A1:A500")
    For Each c In Range("A1:A15")
    If d = c Then
    c.Resize(1, 70).Copy
    Worksheets("Sheet3").Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
    Exit For
    End If
    Next
    Next
    Application.CutCopyMode = False
    Worksheets("Sheet3").Activate
    Range("A1").Select
    End Sub


    Thanks in advance for any help

    Regards
    Tim
    Last edited by timmycl_7; 01-27-2009 at 08:12 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Copying a row based on matching unique values

    Hello Tim,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    03-12-2008
    Posts
    36

    Re: Copying a row based on matching unique values

    Sorry Leith,

    I have posted my query again.

    I have the following code which takes a unique value from 'sheet 1', and searches for the value in 'sheet 2'. If there is a matching value in sheet 2 it will copy the full row into sheet three.

    I need to extend the code so that all values from 'sheet 1' are copied to 'sheet 3' even if there is no matching value in 'sheet 2'. If there is a matching value in 'sheet 2' however I need the entire row to be copied to 'sheet 3'

    See the code I have at the moment.

    Please Login or Register  to view this content.

    Thanks in advance for any help

    Regards
    Tim

+ 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