Cut and Paste Row if "X" is in certain cell

ceereal

New Member
Joined
Oct 3, 2014
Messages
2
I am trying to create a macro that will cut a whole row if the cell in column K is equal to "Product". The Row that was cut must get pasted onto the next worksheet starting from row 2 onward. Also, I need all the cells from the first worksheet to move up once the row has been cut.

Please help.

Thanks,
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try this:

Code:
Option Explicit


Sub DelK()
    Dim sh1 As Worksheet, sh2 As Worksheet
    Set sh1 = Sheets("Sheet1"): Set sh2 = Sheets("Sheet2")
    Dim r1 As Long, r2 As Long
    r1 = sh1.Range("K" & Rows.Count).End(xlUp).Row
    Dim i As Long
    
    Application.ScreenUpdating = False
    For i = r1 To 1 Step -1
    r2 = sh2.Range("A" & Rows.Count).End(xlUp).Row
        If sh1.Range("K" & i) = "Product" Then
        sh1.Range("K" & i).EntireRow.Cut sh2.Range("A" & r2 + 1)
        sh1.Range("K" & i).EntireRow.Delete
        End If
    Next i
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    MsgBox ("completed")
    
End Sub
 
Upvote 0
Code:
Sub moveAndDelete()

    Dim start As Worksheet
    Dim dest As Worksheet
    
    Dim nextRow As Long
    nextRow = 2
    
    Set start = Sheets("Sheet11") 'CHANGE ME
    Set dest = Sheets("Sheet12") 'CHANGE ME


    With start
        For x = .Cells(Rows.Count, "K").End(xlUp).Row To 2 Step -1
            If .Cells(x, 11).Value = "Product" Then
                With .Cells(x, 1).EntireRow
                    dest.Cells(nextRow, 1).EntireRow.Value = .Value
                    .Delete
                End With
                nextRow = nextRow + 1
            End If
        Next x
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,702
Members
449,048
Latest member
81jamesacct

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top