VBA Speed up Copy and paste

hajiali

Well-known Member
Joined
Sep 8, 2018
Messages
626
Office Version
  1. 2016
Platform
  1. Windows
Need help to updating below code where copy and paste option to speed up. Let me know if I need to clear any part of the code. Any information is greatly appreciated.
VBA Code:
LRStar = ActiveSheet.Range("L1")
For i = 2 To LRStar
LRSft = ActiveSheet.Range("J1")
    If LRSft + LRStar > 4001 Then
            MsgBox "THIS WILL EXCEED THE AMOUNT OF DATA THE TOOL ACCEPTS.", vbOKOnly, "IMPORT EXCEEDED"
            Exit Sub
    End If
    Application.EnableEvents = False
    
        If Cells(i, "L") = 1 Then
            Cells(i, "N").Copy
               Application.EnableEvents = False
                Range("B" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "P").Copy
                Range("A" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "V").Copy
                Range("C" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "X").Copy
                Range("D" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
                Cells(LRSft, "G").Value = ans
         End If
Next
    For i = 2 To LRStar
    LRSft = ActiveSheet.Range("J1")
        If Cells(i, "Y") = 1 Then
            Cells(i, "N").Copy
               Application.EnableEvents = False
                Range("A" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "P").Copy
                Range("B" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "S").Copy
                Range("C" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "AM").Copy
                Range("U" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
                Cells(LRSft, "G").Value = ans
         End If
Next

I have also tried

VBA Code:
    If Cells(i, "L") = 1 Then
            Application.EnableEvents = False
            Cells(LRSft, "B").Value = Cells(i, "N")
            Cells(LRSft, "A").Value = Cells(i, "P")
            Cells(LRSft, "C").Value = Cells(i, "V")
            Cells(LRSft, "D").Value = Cells(i, "X")
            Cells(LRSft, "G").Value = ans
     End If
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
try adding

VBA Code:
Application.ScreenUpdating = False

...your code

Application.ScreenUpdating = true
 
Upvote 0
try adding

VBA Code:
Application.ScreenUpdating = False

...your code

Application.ScreenUpdating = true

I have tried the Screen updating where right before the coping and pasting and seems like its not taking effect. I will not be able to add it before all my code as the pasting is in a Loop to the next cell.


VBA Code:
Application.ScreenUpdating = False
            Cells(i, "N").Copy
               Application.EnableEvents = False
                Range("A" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "P").Copy
                Range("B" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "S").Copy
                Range("C" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Cells(i, "AM").Copy
                Range("U" & LRSft).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
                Cells(LRSft, "G").Value = ans
Application.ScreenUpdating = true
 
Upvote 0
Any chance you can post your sheet using XL2BB?

I'd like to see the sample data.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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