I am using this code to move row based on cell value to another sheet. This code is moving the row which contain ok in column A from sheet1 to sheet2. But I need if find ok in row 20 and cloumn A. Then the row will go to 20 nth row to the sheet2. Suppose row 4,7,4,13,42,45,,98,100 contain ok in column A. I need to move that rows to sheet two in same number of row.
row 4 will go to 4rth row in shhet2.
row 7 will go to 7nth row in shhet2.
row 13 will go to 13nth row in shhet2.
It will continue for the next row.
Sub MoveCompleted()
Dim h As Variant
Dim endrow As Integer
Dim OL As Worksheet, Cmp As Worksheet
Set OL = ActiveWorkbook.Sheets("sheet1")
Set Cmp = ActiveWorkbook.Sheets("sheet2")
endrow = OL.Range("A" & OL.Rows.Count).End(xlUp).Row
For h = 2 To endrow
If OL.Cells(h, "A").Value = "ok" Then
OL.Cells(h, "A").EntireRow.Cut Destination:=Cmp.Range("A" & Cmp.Rows.Count).End(xlUp).Offset(1)
End If
Next
End Sub
Bookmarks