Copy and paste row to another worksheet depending on cell value.

Ippon

New Member
Joined
Jan 18, 2012
Messages
39
How do I Copy and paste row to another worksheet depending on cell value. e.g.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Where any cell in column D of a Worksheet named "Clients" contains the word "Employed" then copy that row of the worksheet from Column A to G into the first available blank row in another worksheet named "Employed".<o:p></o:p>
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,
Try this code.

Code:
Sub Copy_Rows()
 
Set rng = Worksheets("Clients").Range(Worksheets("Clients").Range("D1"), Worksheets("Clients").Range("D" & Rows.Count).End(xlUp))
x = 1
    For Each Cell In rng
 
    If Cell.Value = "Employed" Then
    num = Cell.Row
 
    Worksheets("Clients").Range("A" & num & ":" & "G" & num).Copy Destination:=Worksheets("Employed").Range("A" & x)
    x = x + 1
 
    End If
 Next
End Sub
 
Last edited:
Upvote 0
Thanks Dave. Haven't got it working yet but will keep playing with it - I must be doing something wrong
 
Upvote 0
Almost working now - The only issue is that it copies over the existing column lables in the destination worksheet "Employed". ie Copies over A1 to D1. So I guess it's not finding the first blank row? Any ideas on this please.
 
Upvote 0
I spoke too soon - At the risk of being a pain in the neck - it fills from the second row regardless of if it is blank or already contains data - Can it find the first empty row?
 
Upvote 0
Hi,

The code would only do the search once and paste from row 2 down so if you re-run the macro it would overwrite from row 2 down. Instead it should be looking for the next empty cell as stated in your post!

That's not your fault. It's my poor reading.

Try this insted.

Code:
Sub Copy_Rows()
Worksheets("Clients").Select
    Set rng = Worksheets("Clients").Range(Worksheets("Clients").Range("D1"), Worksheets("Clients").Range("D" & Rows.Count).End(xlUp))
    For Each Cell In rng
    
    If Cell.Value = "Employed" Then
    num = Cell.Row
     
    Worksheets("Clients").Range("A" & num & ":" & "G" & num).Copy Destination:=Worksheets("Employed").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
   End If
 Next
End Sub
 
Upvote 0
Thank you very much Daverunt that's great. All working now.
I have learnt a lot about VBA (as a beginner) from your replies and playing with this.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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