Copy rows from sheet 1 to sheet 2 based on 2 cell values

Demer

New Member
Joined
May 5, 2021
Messages
19
Office Version
  1. 365
  2. 2019
  3. 2013
Platform
  1. Windows
Hello I'm trying to move a row from sheet 1 "Chapter to Sheet 2 "Complete" using VBA for instance if A3 = "Cash" and L3 = "Refund" cut copy and paste entire row to Sheet 2 "Complete" and search the other rows if both criteria's are met then cut copy and paste entire row to Sheet 2 "Complete" otherwise don't move the rows. I cant figure this out any help would be much appreciated.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
try this on a copy of your file.

VBA Code:
Sub move_it()

Application.ScreenUpdating = False

Dim rs1 As Worksheet, rs2 As Worksheet
Set rs1 = Sheets("Chapter")
Set rs2 = Sheets("Complete")

lr = rs1.Range("A" & Rows.Count).End(xlUp).Row

For r = 1 To lr

If rs1.Cells(r, "A") = "Cash" And rs1.Cells(r, "L") = "Refund" Then
    rs1.Cells(r, "A").EntireRow.Copy Destination:=rs2.Range("A" & Rows.Count).End(xlUp).Offset(1)
    rs1.Cells(r, "A") = "DELETE ME"
End If

Next r


On Error Resume Next
    With rs1.Range("A1:A" & lr)
        .Replace "DELETE ME", False, xlWhole
        .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
    End With
On Error GoTo 0

Application.ScreenUpdating = True

End Sub

hth,
Ross
 
Upvote 0
Solution
Application.ScreenUpdating = False Dim rs1 As Worksheet, rs2 As Worksheet Set rs1 = Sheets("Chapter") Set rs2 = Sheets("Complete") lr = rs1.Range("A" & Rows.Count).End(xlUp).Row For r = 1 To lr If rs1.Cells(r, "A") = "Cash" And rs1.Cells(r, "L") = "Refund" Then rs1.Cells(r, "A").EntireRow.Copy Destination:=rs2.Range("A" & Rows.Count).End(xlUp).Offset(1) rs1.Cells(r, "A") = "DELETE ME" End If Next r On Error Resume Next With rs1.Range("A1:A" & lr) .Replace "DELETE ME", False, xlWhole .SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete End With On Error GoTo 0 Application.ScreenUpdating = True
Thank you very much. This works great I just replaced the delete me with "A" to keep the information in that column
 
Upvote 0
Hi how would you move rows if you had either word ?

for example you have row 3 / Col F with Cash and have row 4 / col W with Refund? (bearing in mind other rows may have both words)
Can you move both these rows? Also a loop would be useful where the number of rows is loads. to prevent manual verification checks
 
Upvote 0
I have amended the code below to check col F which may have a 1. Now i also have other columns with other values which require moving to Sheet 2. I would like some help one moving rows which have various selections. Like col F has a 1 then move row. Col W has a 3 then move rove, col X has a Tree then move row.

Thanks in advance




Sub move_1s()

Application.ScreenUpdating = False

Dim rs1 As Worksheet, rs2 As Worksheet
Set rs1 = Sheets("sheet1")
Set rs2 = Sheets("Sheet2")

lr = rs1.Range("A" & Rows.Count).End(xlUp).Row

For r = 1 To lr


If rs1.Cells(r, "F") = "1" Then
rs1.Cells(r, "A").EntireRow.Copy Destination:=rs2.Range("A" & Rows.Count).End(xlUp).Offset(1)
rs1.Cells(r, "A") = "DELETE ME"


End If

Next r


On Error Resume Next
With rs1.Range("A1:A" & lr)
.Replace "DELETE ME", False, xlWhole
.SpecialCells(xlCellTypeConstants, 4).EntireRow.Delete
End With
On Error GoTo 0

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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