I'm trying to run through a large dataset of over 80,000 rows. Copying an entire row if column C contains any text, starting from row 6. Below is my Macro i currently have, is there any way in optimizing it so that it doesn't take so long? the current code runs through row by row.
Sub testIt()
Dim r As Long, endRow As Long, pasteRowIndex As Long
endRow = 100000
pasteRowIndex = 1
For r = 6 To endRow 'Loop through Stocks to Sell and search for your criteria
If Cells(r, Columns("C").Column).Value <> Empty Then
'Copy the current row
Rows(r).Select
Selection.Copy
'Switch to the sheet where you want to paste it & paste
Sheets("Stocks to Sell").Select
ActiveSheet.Rows(pasteRowIndex).Select
Selection.PasteSpecial Paste:=xlPasteValues
'Next time you find a match, it will be pasted in a new row
pasteRowIndex = pasteRowIndex + 1
'Switch back to your table & continue to search for your criteria
Sheets("Unrealized Gains Report").Select
End If
If Cells(r, Columns("D").Column).Value = "yes" Then 'Found
'Copy the current row
Rows(r).Select
Selection.Copy
'Switch to the sheet where you want to paste it & paste
Sheets("Gmma Positions").Select
ActiveSheet.Rows(pasteRowIndex).Select
Selection.PasteSpecial Paste:=xlPasteValues
'Next time you find a match, it will be pasted in a new row
pasteRowIndex = pasteRowIndex + 1
'Switch back to your table & continue to search for your criteria
Sheets("Unrealized Gains Report").Select
End If
Next r
End Sub
I'm new to VBA, so the code is a little basic. Any help would be appreciated