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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

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