+ Reply to Thread
Results 1 to 8 of 8

Code to copy entire row to another worksheet if cell has specific value

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    North Bay, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    60

    Code to copy entire row to another worksheet if cell has specific value

    Hello,

    I need a code to copy an entire row to another worksheet if a specific cell has a certain value...

    For example:

    If cell B4 is equal to 200, copy entire row 4 to another worksheet...

    Any help?

    Thanks again,

    Pat.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,526

    Re: Code to copy entire row to another worksheet if cell has specific value

    With the supplied information, this might do it


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-17-2009
    Location
    Port St. Lucie, FL
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Code to copy entire row to another worksheet if cell has specific value

    GenericPat,
    Try this to see if it might get you headed in the right direction:
    Please Login or Register  to view this content.

    The Worksheets("Sheet1") and ("Sheet2") you can substitute for the worksheets in your workbook.
    hth,
    Dennis

  4. #4
    Registered User
    Join Date
    10-01-2012
    Location
    North Bay, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: Code to copy entire row to another worksheet if cell has specific value

    Doesn't seem to be working on my end

    Any chance you can make a simplified version of Excel with the intergrated code and post it?

    Thanks,

    Pat.

  5. #5
    Registered User
    Join Date
    07-31-2012
    Location
    Tampa
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Code to copy entire row to another worksheet if cell has specific value

    Try This..




    Sub Copy_Row()
    Application.ScreenUpdating = False
    Dim varSourceRow As Integer
    Dim varTargetRow As Integer
    'Determine the next available row on sheet2
    Sheets("Sheet2").Select
    varTargetRow = Cells(5000, 1).End(xlUp).Offset(1, 0).row
    'Set top row for sheet1
    varSourceRow = 2
    Sheets("Sheet1").Select
    Do 'Loop through all rows on Sheet1 and copy if cell value is 200
    Cells(varSourceRow, 1).Select
    If ActiveCell.Offset(0, 0).Value = "200" Then
    Range(Cells(varSourceRow, 1), Cells(varSourceRow, 180)).Select
    Selection.Copy

    Sheets("Sheet2").Select
    Range(Cells(varTargetRow, 1), Cells(varTargetRow, 180)).Select
    ActiveSheet.Paste

    Sheets("Sheet1").Select
    varSourceRow = varSourceRow + 1
    varTargetRow = varTargetRow + 1


    Else
    varSourceRow = varSourceRow + 1


    End If


    Loop Until ActiveCell.Value = ""
    End Sub

  6. #6
    Registered User
    Join Date
    10-01-2012
    Location
    North Bay, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: Code to copy entire row to another worksheet if cell has specific value

    Ok it doesnt seem to work could you write something for my updated version...

    I want all the rows in which the cells in Column H are greater then 4 999 999.99$ in sheet (Base de données) to be copied to sheet (Profil +5 Million $) starting on row 2!

    Thanks

    Pat.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,526

    Re: Code to copy entire row to another worksheet if cell has specific value

    Something like this possibly.

    Please Login or Register  to view this content.
    If you have columns past Column H, code needs to be adjusted for that.
    Let us know.

    Good Luck

    John

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,526

    Re: Code to copy entire row to another worksheet if cell has specific value

    Here is another approach. (See attached)


    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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