Cut and pastimg rows with vba

Johnreg

New Member
Joined
Feb 20, 2020
Messages
7
Office Version
  1. 365
Hi all,

First of apologies I know this topic has been discussed a lot but any example I have tried to use doesnt work.

So in column A has a job type and column E has if its completed.

So for example job type would electrical, plumbing and engineering.

So what I need to happen is if a row contains and of the above job types and completed in column E the row cuts to a different workbook.



As you might I have guessed I am very new to VBA and any help / starting point would be much appreciated.

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
try this.
make a new sheet and name it Completed

VBA Code:
Sub Move_Compelted()

Dim rs As Worksheet
Set rs = Worksheets("Completed")

For r = 2 To Range("A" & Rows.Count).End(xlUp).Row

If (Cells(r, "A") = "electrical" Or Cells(r, "A") = "plumbing" Or Cells(r, "A") = "engneering") And Cells(r, "E") <> "" Then

wr = rs.Range("A" & Rows.Count).End(xlUp).Row + 1
Rows(r).Copy Destination:=rs.Range("A" & wr)
Rows(r).ClearContents
End If

Next r
End Sub
 
Upvote 0
Hi,

Thanks so much for response.

Probably should have said the each row will have to got into a different sheet on different workbook.

So basically I have workbook called finished and sheets called plumbing electrical engineering. So depending on the job type it will have to go into a different sheet.

Sorry if this make it much more complicated.
 
Upvote 0
VBA Code:
Sub Move_Compelted()

Dim rs As Worksheet

For r = 2 To Range("A" & Rows.Count).End(xlUp).Row

If Cells(r, "A") = "electrical" And Cells(r, "E") <> "" Then Set rs = Worksheets("electrical")
If Cells(r, "A") = "plumbing" And Cells(r, "E") <> "" Then Set rs = Worksheets("plumbing")
If Cells(r, "A") = "engneering" And Cells(r, "E") <> "" Then Set rs = Worksheets("engneering")

wr = rs.Range("A" & Rows.Count).End(xlUp).Row + 1
Rows(r).Copy Destination:=rs.Range("A" & wr)
Rows(r).ClearContents
End If

Next r
End Sub
 
Upvote 0
the code above wont work

VBA Code:
Sub Move_Compelted()

Dim rs As Worksheet
For r = 2 To Range("A" & Rows.Count).End(xlUp).Row

If Cells(r, "A") = "electrical" And Cells(r, "E") <> "" Then
    Set rs = Worksheets("electrical")
    GoSub doit
End If

If Cells(r, "A") = "plumbing" And Cells(r, "E") <> "" Then
    Set rs = Worksheets("plumbing")
    GoSub doit
End If
  
If Cells(r, "A") = "engneering" And Cells(r, "E") <> "" Then
    Set rs = Worksheets("engneering")
    GoSub doit
End If

Next r

Exit Sub

doit:
wr = rs.Range("A" & Rows.Count).End(xlUp).Row + 1
Rows(r).Copy Destination:=rs.Range("A" & wr)
Rows(r).ClearContents
Return

End Sub
 
Upvote 0
Hi,

Thanks that worked perfectly much appreciated.

Just wondering could you explain this part of the code "For r = 2".
 
Upvote 0
it create a loop. it starts at row 2 and loop thru all rows you have in column "A"

 
Upvote 0
the wr finds the next blank row at the bottom of the destinatino sheet to write the data to.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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