+ Reply to Thread
Results 1 to 7 of 7

help with match, copy, paste please

  1. #1
    Mona
    Guest

    help with match, copy, paste please

    I have example data on worksheet ("results"):

    A B C D
    1 maybe car
    8 maybe van 03/04/2007

    I will randomly change any or all of the data ONLY in columns B,C, or D to
    something like this:

    A B C D
    1 maybe car 09/12/2006
    8 no van 05/26/2007

    I would like help in writting the code to COPY the entire row/rows from
    "results" and paste to a "master" worksheet when column A ("results") matches
    column A ("master"). Column A in both "master" and "results" are unique
    values.

    thank you !!

  2. #2
    Jim Thomlinson
    Guest

    RE: help with match, copy, paste please

    Why not just use VLookup worksheet function?
    --
    HTH...

    Jim Thomlinson


    "Mona" wrote:

    > I have example data on worksheet ("results"):
    >
    > A B C D
    > 1 maybe car
    > 8 maybe van 03/04/2007
    >
    > I will randomly change any or all of the data ONLY in columns B,C, or D to
    > something like this:
    >
    > A B C D
    > 1 maybe car 09/12/2006
    > 8 no van 05/26/2007
    >
    > I would like help in writting the code to COPY the entire row/rows from
    > "results" and paste to a "master" worksheet when column A ("results") matches
    > column A ("master"). Column A in both "master" and "results" are unique
    > values.
    >
    > thank you !!


  3. #3
    Tom Ogilvy
    Guest

    RE: help with match, copy, paste please

    Sub CopyResults()
    Dim res as Variant
    Dim resRng as Range
    Dim masRng as Range
    Dim rng as Range
    With worksheets("Results")
    set resRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))

    With worksheets("Master")
    set masRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    end with
    for each cell in resRng
    res = application.Match(cell.value, masRng,0)
    if not iserror(res) then
    cell.Entirerow.copy masRng(res)
    else
    set rng = .cells(rows.count,1).end(xlup)(2)
    cell.entirerow.copy rng
    end if
    Next
    End With
    End Sub

    Test on a copy of your workbook

    --
    Regards,
    Tom Ogilvy


    "Mona" wrote:

    > I have example data on worksheet ("results"):
    >
    > A B C D
    > 1 maybe car
    > 8 maybe van 03/04/2007
    >
    > I will randomly change any or all of the data ONLY in columns B,C, or D to
    > something like this:
    >
    > A B C D
    > 1 maybe car 09/12/2006
    > 8 no van 05/26/2007
    >
    > I would like help in writting the code to COPY the entire row/rows from
    > "results" and paste to a "master" worksheet when column A ("results") matches
    > column A ("master"). Column A in both "master" and "results" are unique
    > values.
    >
    > thank you !!


  4. #4
    Mona
    Guest

    RE: help with match, copy, paste please

    I could. But I am putting buttons on the worksheet so user has the ability
    to change master with the click of the button

    "Jim Thomlinson" wrote:

    > Why not just use VLookup worksheet function?
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "Mona" wrote:
    >
    > > I have example data on worksheet ("results"):
    > >
    > > A B C D
    > > 1 maybe car
    > > 8 maybe van 03/04/2007
    > >
    > > I will randomly change any or all of the data ONLY in columns B,C, or D to
    > > something like this:
    > >
    > > A B C D
    > > 1 maybe car 09/12/2006
    > > 8 no van 05/26/2007
    > >
    > > I would like help in writting the code to COPY the entire row/rows from
    > > "results" and paste to a "master" worksheet when column A ("results") matches
    > > column A ("master"). Column A in both "master" and "results" are unique
    > > values.
    > >
    > > thank you !!


  5. #5
    Mona
    Guest

    RE: help with match, copy, paste please

    Tom-
    this is perfect! thank you

    "Tom Ogilvy" wrote:

    > Sub CopyResults()
    > Dim res as Variant
    > Dim resRng as Range
    > Dim masRng as Range
    > Dim rng as Range
    > With worksheets("Results")
    > set resRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    >
    > With worksheets("Master")
    > set masRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    > end with
    > for each cell in resRng
    > res = application.Match(cell.value, masRng,0)
    > if not iserror(res) then
    > cell.Entirerow.copy masRng(res)
    > else
    > set rng = .cells(rows.count,1).end(xlup)(2)
    > cell.entirerow.copy rng
    > end if
    > Next
    > End With
    > End Sub
    >
    > Test on a copy of your workbook
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Mona" wrote:
    >
    > > I have example data on worksheet ("results"):
    > >
    > > A B C D
    > > 1 maybe car
    > > 8 maybe van 03/04/2007
    > >
    > > I will randomly change any or all of the data ONLY in columns B,C, or D to
    > > something like this:
    > >
    > > A B C D
    > > 1 maybe car 09/12/2006
    > > 8 no van 05/26/2007
    > >
    > > I would like help in writting the code to COPY the entire row/rows from
    > > "results" and paste to a "master" worksheet when column A ("results") matches
    > > column A ("master"). Column A in both "master" and "results" are unique
    > > values.
    > >
    > > thank you !!


  6. #6
    Mona
    Guest

    RE: help with match, copy, paste please

    Tom-
    this just came up and I can't seem to figure out. Using the "perfect" code
    below work when I have 2 or more rows of data. But if I only have 1 row of
    data I get an error but it actually updates my "master". From time to time I
    will have only one row of data. Can you help me with this one? Thanks!

    "Tom Ogilvy" wrote:

    > Sub CopyResults()
    > Dim res as Variant
    > Dim resRng as Range
    > Dim masRng as Range
    > Dim rng as Range
    > With worksheets("Results")
    > set resRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    >
    > With worksheets("Master")
    > set masRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    > end with
    > for each cell in resRng
    > res = application.Match(cell.value, masRng,0)
    > if not iserror(res) then
    > cell.Entirerow.copy masRng(res)
    > else
    > set rng = .cells(rows.count,1).end(xlup)(2)
    > cell.entirerow.copy rng
    > end if
    > Next
    > End With
    > End Sub
    >
    > Test on a copy of your workbook
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Mona" wrote:
    >
    > > I have example data on worksheet ("results"):
    > >
    > > A B C D
    > > 1 maybe car
    > > 8 maybe van 03/04/2007
    > >
    > > I will randomly change any or all of the data ONLY in columns B,C, or D to
    > > something like this:
    > >
    > > A B C D
    > > 1 maybe car 09/12/2006
    > > 8 no van 05/26/2007
    > >
    > > I would like help in writting the code to COPY the entire row/rows from
    > > "results" and paste to a "master" worksheet when column A ("results") matches
    > > column A ("master"). Column A in both "master" and "results" are unique
    > > values.
    > >
    > > thank you !!


  7. #7
    Tom Ogilvy
    Guest

    Re: help with match, copy, paste please

    My guess would be to change
    set resRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))

    to

    if .cells(1,1).End(xldown).row <> rows.count then
    set resRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    else
    set resRng = .Range("A1")
    End if

    --
    regards,
    Tom Ogilvy

    "Mona" <Mona@discussions.microsoft.com> wrote in message
    news:AB90A163-6B49-4FB9-B14C-66549DEED555@microsoft.com...
    > Tom-
    > this just came up and I can't seem to figure out. Using the "perfect"
    > code
    > below work when I have 2 or more rows of data. But if I only have 1 row
    > of
    > data I get an error but it actually updates my "master". From time to
    > time I
    > will have only one row of data. Can you help me with this one? Thanks!
    >
    > "Tom Ogilvy" wrote:
    >
    >> Sub CopyResults()
    >> Dim res as Variant
    >> Dim resRng as Range
    >> Dim masRng as Range
    >> Dim rng as Range
    >> With worksheets("Results")
    >> set resRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    >>
    >> With worksheets("Master")
    >> set masRng = .Range(.Cells(1,1),.cells(1,1).End(xldown))
    >> end with
    >> for each cell in resRng
    >> res = application.Match(cell.value, masRng,0)
    >> if not iserror(res) then
    >> cell.Entirerow.copy masRng(res)
    >> else
    >> set rng = .cells(rows.count,1).end(xlup)(2)
    >> cell.entirerow.copy rng
    >> end if
    >> Next
    >> End With
    >> End Sub
    >>
    >> Test on a copy of your workbook
    >>
    >> --
    >> Regards,
    >> Tom Ogilvy
    >>
    >>
    >> "Mona" wrote:
    >>
    >> > I have example data on worksheet ("results"):
    >> >
    >> > A B C D
    >> > 1 maybe car
    >> > 8 maybe van 03/04/2007
    >> >
    >> > I will randomly change any or all of the data ONLY in columns B,C, or D
    >> > to
    >> > something like this:
    >> >
    >> > A B C D
    >> > 1 maybe car 09/12/2006
    >> > 8 no van 05/26/2007
    >> >
    >> > I would like help in writting the code to COPY the entire row/rows
    >> > from
    >> > "results" and paste to a "master" worksheet when column A ("results")
    >> > matches
    >> > column A ("master"). Column A in both "master" and "results" are
    >> > unique
    >> > values.
    >> >
    >> > thank you !!




+ 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