I am trying to write a script which copies a row from Sheet 1 to Sheet 2, if the value for the first column of Sheet 1 is greater or equal to 10.
Sub Macro1()
Cells(1, 1).Select
For i = 1 To ActiveCell.SpecialCells(xlLastCell).Row
Cells(i, 1).Select
If ActiveCell.Value >= 10 Then
Rows(ActiveCell.Row).Select
Rows(i & ":").Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End If
Next i
End Sub
This is similar to the first answer, but a few differences. Here's some notes:
Here is the code:
Sub CopyRows()
Dim cell As Range
Dim lastRow As Long, i As Long
lastRow = Range("A" & Rows.Count).End(xlUp).Row
i = 1
For Each cell In Sheets(1).Range("A1:A" & lastRow)
If cell.Value >= 10 Then
cell.EntireRow.Copy Sheets(2).Cells(i, 1)
i = i + 1
End If
Next
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With