Copy Row

Geoff Varner

New Member
Joined
Mar 17, 2009
Messages
18
Happy Monday!

I would like to write code where an entire row is copied based on the contents of a particular cell in the row and then paste that row on a different sheet in the workbook. For example:

1 2 d a b
1 3 d c b
1 4 d a b

I would like for the code to look for the letter c in the 4th column then copy the entire row and past it.

Can anyone help please?

Thanks,

Geoff
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi,

Try;

Code:
Sub MoveRows()

Dim lRow As Long

lRow = Range("A" & Rows.count).End(xlUp).Row

Columns("D").AutoFilter Field:=1, Criteria1:="c"
Range("A1:E" & lRow).SpecialCells(xlCellTypeVisible).Copy Sheets(2).Range("A1")
ActiveSheet.ShowAllData

End Sub
 
Upvote 0
I think this will work but can I specify the name of a worksheet to copy from as well. Copy from sheet (CC New Hire) to sheet (SPOKC).

Thanks.
 
Upvote 0
Try this:-
Alter destination sheet to suit.
NB:- This code will add Additional "c" Data to subsequent rows in destination sheet.
Code:
Sub cc()
Dim Rng As Range, Dn As Range, Last As Long
With Sheets("Sheet43")
Last = .Range("A" & Rows.Count).End(xlUp).Row + 1
End With
Set Rng = Range(Range("D1"), Range("D" & Rows.Count).End(xlUp))
    For Each Dn In Rng
        If Dn.Value = "c" Then
            Dn.EntireRow.Copy Sheets("Sheet43").Cells(Last, "A")
        End If
Next Dn
End Sub
Regards Mick
 
Upvote 0
Hi,

Of course, I have wrapped it all within a With Statement, just change the bold referenece to match your Sheet name;

Code:
Sub MoveRows()

Dim lRow As Long

With Sheets("Your Sheet")
    lRow = .Range("A" & Rows.count).End(xlUp).Row
    .Columns("D").AutoFilter Field:=1, Criteria1:="c"
    .Range("A1:E" & lRow).SpecialCells(xlCellTypeVisible).Copy Sheets(2).Range("A1")
    .ShowAllData
End With

End Sub

Hi Mick,

The Autofilter Method is in my opinion a lot lot more efficient than the loop.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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