I'm new with writing macros. When I run my macro on big datasets, it seems it is freezing. I assume it's because of running through the dataset. Is there any way of fixing it or getting it to run smoothly?
' Second step, match accts that have holdings in the sell List and paste them to MasterSheets
Sub testIt()
Dim r As Long, endRow As Long, pasteRowIndex As Long
pasteRowIndex = 1
For r = 6 To 100000
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