How do I cut instead of copy?

  • Thread starter Thread starter Mary
  • Start date Start date
M

Mary

Hi

I am using some code to try and extract rows from one
spreadsheet based on the value in a particular column
matching that in another.

The code i have at the moment will copy the row but not
cut it also if there are 3 rows in my column matching the
criteria it wont copy all three it will just take one.

Do you know where the code is missing?

Mary
 
Sorry this is the code I am using!!

Sub MoveMatches()

Dim wsSrc As Worksheet
Dim wsFind As Worksheet
Dim wsDest As Worksheet
Dim rCell As Range
Dim rFound As Range

Set wsSrc = Workbooks("1.xls").Sheets(1)
Set wsFind = Workbooks("2.xls").Sheets(1)
Set wsDest = Workbooks("2.xls").Sheets(2)

For Each rCell In wsSrc.Columns(1).Cells
Set rFound = wsFind.Columns(2).Find(rCell.Value)

If Not rFound Is Nothing Then
rCell.EntireRow.Cut wsDest.Range("A65536").End
(xlUp).Offset(1, 0)
End If

Next rCell

End Sub
 
try this
rCell.EntireRow.Cut destination:=wsDest.Range("A65536").End
(xlUp).Offset(1, 0)

you introduce <destination:=> after <cut> i.e. cut(space)destination:=

I have not verified this . I have verified the following on the same
sheet(activesheet)

range("a1").EntireRow.Cut destination:=range("a10")
 
The end result seems as though I have spent a long time
going through each row with the egg timer showing.. and
then .. the row has been cut from 1.xls into 2.xls sheet2

I have another spreadsheet which I am using to hold the
button on to click and start off the procedure.

Could this be why there are problems?

Where should the code be in a module?

1.xls?
2.xls?
menu.xls?

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top