Vba to move row from one sheet to another

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
This event code would execute when changes are made in column H. You can modify it for the row to move if it is not the target row. The code goes in the worksheet code module.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        If LCase(Target.Value) = "closed" Then
            Target.EntireRow.Cut Sheets(2).Cells(Rows.Count, 1).End(xlUp)(2)
        End If
    End If
End Sub
 
Last edited:
Upvote 0
thanks for this, it worked. But I have a running list of issues in sheet1, when I "close" an issue i need all the issues marked as closed moving to sheet2. This code deletes and replaces each item that gets marked as closed. It keeps putting them in row 2. Is there a way to have the issues getting closed to end up in a list on sheet 2. Thank you
 
Upvote 0
thanks for this, it worked. But I have a running list of issues in sheet1, when I "close" an issue i need all the issues marked as closed moving to sheet2. This code deletes and replaces each item that gets marked as closed. It keeps putting them in row 2. Is there a way to have the issues getting closed to end up in a list on sheet 2. Thank you
 
Upvote 0
Your column A must be blank, try this modified version. Delete the first one.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim lr As Long
    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        If LCase(Target.Value) = "closed" Then
            lr = Sheets(2).Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1
            Target.EntireRow.Cut Sheets(2).Cells(lr, 1)
        End If
    End If
End Sub
 
Last edited:
Upvote 0
I need data in the A column. It worked for couple then gave me run time error 91 "object variable or with block variable not set? Sorry Im real new
 
Upvote 0
Delete the second version and try this modified version.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim lr As Long
    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        If Target <> "" Then
            If LCase(Target.Value) = "closed" Then
                lr = Sheets(2).Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1
                Target.EntireRow.Cut Sheets(2).Cells(lr, 1)
            End If
        End If
    End If
End Sub

I am not sure why you got that particular error message, but hopefully this will avoid it.
 
Upvote 0
I got the same message, and the debug highlighted this line of the code lr = Sheets(2).Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1
 
Upvote 0
If the entire sheet 2 is blank then you would get that message because there is no previous for it to go to. This should fix that.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Dim lr As Long
    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        If Target <> "" Then
            If LCase(Target.Value) = "closed" Then
                If Application.CountA(Sheets(2).Rows(1)) = 0 Then
                    Target.EntireRow.Cut Sheets(2).Range("A1")
                Else
                    lr = Sheets(2).Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row + 1
                    Target.EntireRow.Cut Sheets(2).Cells(lr, 1)
                End If
            End If
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,958
Messages
6,181,998
Members
453,081
Latest member
MenanceSon

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