1

Ive been trying to figure out how to make this work for a while now, so I'll give you guys a try!

I have a list of facts in Sheet1 from column A-Q and row 1-5000.

In column E im going to write different words as I go down the list. Lets just say that the word will be "Yes" or "No".

I want a macro that will copy all the rows with the word "Yes" in, into Sheet2.

I have found a way that works, but the problem is that this will copy into row 2 in sheet 2 always. So, lets say i change some of the info on Sheet2 and after a week i use the macro again. This will make the macro overwrite the changes ive done.

Not sure if you guys understand what im trying to say here, but I hope so!.

I would like a macro that MOVE the row, instead of Copy/paste it. This will make the number of rows on Sheet1 grow smaller, and I can change the info as i go down the list on sheet2.

I hope you get what im asking.

Below is the macro im using now:

   Sub Makro2()

 Dim LSearchRow As Long
 Dim LCopyToRow As Long
 Dim wksInput As Worksheet
 Dim wksOutput As Worksheet

 On Error GoTo Err_Execute

 Set wksOutput = Sheets("Sheet2")

 Set wksInput = ThisWorkbook.Worksheets("Sheet1")

 LCopyToRow = 2
 For LSearchRow = 2 To wksInput.UsedRange.Rows.Count
     If wksInput.Cells(LSearchRow, 2) = "TEST" Then
         wksInput.Rows(LSearchRow).Copy wksOutput.Cells(LCopyToRow, 1)
         LCopyToRow = LCopyToRow + 1
     End If
 Next LSearchRow

 With wksInput
     .Activate
     .Range("A3").Select
 End With

 Exit Sub
 Err_Execute:
     MsgBox "An error occurred. Number: " & Err.Number & " Description: " &  Err.Description
 End sub
4

1 回答 1

0

代替:

LCopyToRow=2

和:

With wksOutput.UsedRange
    LCopyToRow = .Rows.Count + .Row
End With
于 2013-09-14T14:52:29.237 回答