VBA Optimization

MKader

New Member
Joined
May 15, 2015
Messages
19
Dear All,

Kindly need your assistance with the below code - How to make it run faster - it takes almost 1 min to find the data and copy and paste - all open windows freeze and nothing is working properly till the process ends,

awaiting your kind feedback,


Code:
Sub CopyData()Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False


Dim lRow As Long


lRow = Range("A" & Rows.Count).End(xlUp).Row


Sheets("Raw").Select


For Each cell In Range("J7:J" & Rows.Count)
    If cell = "X" Or cell = "Y" Then    cell.EntireRow.Copy
    Sheets("New").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteAll
    cell.EntireRow.ClearContents
    End If
    
Next cell


With ActiveSheet.AutoFilterMode = False
    With Range("A7", Range("A" & Rows.Count).End(xlUp)).AutoFilter 1, "" On Error Resume Next    .Offset(1).SpecialCells(4).EntireRow.Delete
    End With
    
    .AutoFilterMode = False
End With


Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.CutCopyMode = False


Sheets("New").Select


End Sub


Thanks,
MK
 
Last edited by a moderator:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Since you're filtering already, why don't you just filter for the values you want, copy the visible cells o the other sheet, then delete the visible rows?
 
Upvote 0

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top