+ Reply to Thread
Results 1 to 7 of 7

Cut and Paste entire row to new worksheet based on criteria in 1 cell

Hybrid View

  1. #1
    Registered User
    Join Date
    09-10-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Cut and Paste entire row to new worksheet based on criteria in 1 cell

    I currently have a piece of code run from a button which looks at the value in column 7 of a worksheet, if the column = "Completed" the code will then select the entire row and delete it.

    What I would like the code to do instead is simply cut and paste the row to the next empty row of a new worksheet then delete the empty row left by the original.

    Current code is:
    For i = 2 To 199
    
    If ActiveSheet.cells(i, 7).Value = "Completed" Then
    cells(i, 7).EntireRow.Delete
    
    i = 1 + i
    End If
    Next i
    
    End Sub
    All suggestions much welcomed
    Many thanks
    KS

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Cut and Paste entire row to new worksheet based on criteria in 1 cell

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Cut and Paste entire row to new worksheet based on criteria in 1 cell

    You have not provided the initial part of your code, so is this code triggered by a worksheet change / selection change event? Or is the code triggered by a button?

  4. #4
    Registered User
    Join Date
    09-10-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Cut and Paste entire row to new worksheet based on criteria in 1 cell

    Sorry it is noted in my first line...it is triggered from a button.

    Thanks

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Cut and Paste entire row to new worksheet based on criteria in 1 cell

    Oops my bad. Sorry.

    Try this code
    Option Explicit
    
    Sub copy_completed()
    Dim i As Long, lrow As Long
    
    Application.ScreenUpdating=False
    
    With Worksheets("Sheet1")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = lrow To 2 Step -1
            If .Range("G" & i).Value = "Completed" Then
                .Rows(i).Copy Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                .Rows(i).Delete
            End If
        Next i
    End With
    
    Application.ScreenUpdating=True
    
    End Sub

    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  6. #6
    Registered User
    Join Date
    09-10-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Cut and Paste entire row to new worksheet based on criteria in 1 cell

    That's great, thanks for your help!

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Cut and Paste entire row to new worksheet based on criteria in 1 cell

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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