Solved Move row to different Worksheet

December 16, 2015 at 13:39:03
Specs: Windows 7
Hello. I have no background in VBA so I'm a little lost trying to follow some of these other responses.

I have a list of data on Worksheet 1. In column A, using a 0 or a 1, I have distinguished if the cell next to it (B2) contains a "/". If B2 contains a "/" I would like to have the whole row copied and moved to Worksheet 2.

If cell A contains a "0", the cell does not contain a "/". If cell A contains a "1" it does contain a "/".

Can someone please help me with this? Thank you!

See More: Move row to different Worksheet

Report •

December 17, 2015 at 16:10:35
✔ Best Answer
I can't take credit for this, I found it here:

I simply modified it to suit your requests.

Sub MyCopy()
'move rows from sheet 1 to sheet 2 if column A has a 1 in it.
'for Move Row into new sheet based on cell valueDim Check As Range
lastrow = Worksheets("Sheet1").UsedRange.Rows.Count
lastrow2 = Worksheets("Sheet2").UsedRange.Rows.Count
If lastrow2 = 1 Then
    lastrow2 = 0
End If
Do While Application.WorksheetFunction.CountIf(Range("A:A"), 1) > 0
    Set Check = Range("A1:A" & lastrow)
    For Each Cell In Check
        If Cell = 1 Then
            Cell.EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & lastrow2 + 1)
            lastrow2 = lastrow2 + 1
        End If
End Sub

Worksheets must be named Sheet1 and Sheet2, else change the names
in the macro at the lines that reads:

lastrow = Worksheets("Sheet1").UsedRange.Rows.Count
lastrow2 = Worksheets("Sheet2").UsedRange.Rows.Count

I tested it a bit and it seems to work for me, see how it works for you.


message edited by mmcconaghy

Report •
Related Solutions

Ask Question