Excel VBA runs "painfully" slow to copy filtered and paste

Cakz Primz

Board Regular
Joined
Dec 4, 2016
Messages
102
Office Version
  1. 365
Platform
  1. Windows
Dear All,

I am using Office 365, and I need to filter, copy visible only from one book to another workbook.
The data source is around 35,000 rows, from column A to AK.

With the code below, it runs "painfully" slow to copy the filtered range, visible cell only and paste it onto another workbook.
I need your expertise suggestions to find the solution.

VBA Code:
Sub CopyPaste()
    With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    .DisplayStatusBar = False
  
    Windows("RFM Log.xlsx").Activate
    Dim wb As Workbook: Set wb = ThisWorkbook
    Dim twb As Workbook
    Dim ws As Worksheet
    Dim tws As Worksheet
    Set wb = Workbooks("RFM.xlsx") 'source workbook
    Set ws = wb.Sheets("RFM - Register") 'source worksheet
    Set twb = Workbooks("PO.xlsb") 'target workbook
    Set tws = twb.Sheets("RFM Reg") 'target worksheet     
    Dim lRow As Long
    lRow = Cells(Rows.Count, 1).End(xlUp).Row

    With ws
    .Range("A2:AK" & lRow).AutoFilter Field:=4, Criteria1:="1", Operator:=xlFilterValues
    .Range("A3:B" & lRow).SpecialCells(xlCellTypeVisible).Copy
    With tws
    .Range("A3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    End With
    End With
    
    Set rng = tws.Range("D3:D50000")
    With ws
    .Range("D3:D50000").SpecialCells(xlCellTypeVisible).Copy
    With tws
    .Range("C3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    End With
    End With
    
    With ws
    .Range("H3:J50000").SpecialCells(xlCellTypeVisible).Copy
    With tws
    .Range("D3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    End With
    End With
    
    With ws
    .Range("N3:Q50000").SpecialCells(xlCellTypeVisible).Copy
    With tws
    .Range("G3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    End With
    End With
    
    With ws
    .Range("S3:AG50000").SpecialCells(xlCellTypeVisible).Copy
    With tws
    .Range("K3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    End With
    End With

    With ws
    .Range("AK3:AK50000").SpecialCells(xlCellTypeVisible).Copy
    With tws
    .Range("Z3").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    End With
    End With
        
    wb.Close savechanges:=False
    
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    .DisplayStatusBar = True
    End With
End Sub

I do really hope that someone could help me.
Thank you very much, really appreciate for your time.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
What does your data look like. Is it all values or do you have formulas mixed in as well.
 
Upvote 0
Can you post a representative sample of your data- preferably using XL2BB...
 
Upvote 0
RFM.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAK
2RFM. NO.MATERIAL TYPESEQRFM CountPO COUNTDR PO COUNTPR CountLOCATION SITE/JAKARTA/CENAIBUYERDETAILED DESCRIPTION (Duplicate value in red highlight)RFM SUBJECT QTY UOMUSERDISCILPINE 2DISCIPLINERFM RECEIVEDDATEBidder List (write bidder name/sole vendor)RFQ issue date Offer Receipt (Date-bidder)TBE receipt date CBE approved date Selected Vendor CHARGEABLE PARTYPAMF Number (CSTS-PAMF-FGRS-XXXX)PAMF StatusPAMF APPROVAL DATEPR NO.PO NO.PO DATEDelivery DatePO Issuance StatusDRAFT PO / PO Under Circulation ApprovalPO Acknowledgment (date) QTY DEL BALANCE QTYDELIVERY STATUS
3207611101SITEWINAVINYL TAPE 2" 3M 471 LIGHT BLUE100ROLLTAUFIK ISMAIL#N/ACOMM03-Jan-20MAKSIMAN/A#N/A#N/A#N/AN/AN/A#N/A25-Jan-20CLOSEDN/A1000COMPLETED
4207620000SITEWINAPLASTIC WRAPPING50ROLLTAUFIK ISMAIL#N/ACOMM03-Jan-20MAKSIMAN/A#N/A#N/A#N/AN/AN/A#N/A25-Jan-20CLOSEDN/A#N/A500COMPLETED
5207630000SITEWINAHAND GLOVE MAXIFLEX SIXE 810PAATAUFIK ISMAIL#N/ACOMM03-Jan-20MAKSIMAN/A#N/A#N/A#N/AN/AN/A#N/A25-Jan-20CLOSEDN/A#N/A100COMPLETED
6207640000SITEWINAHAND GLOVE MAXIFLEX SIXE 910PAATAUFIK ISMAIL#N/ACOMM03-Jan-20MAKSIMAN/A#N/A#N/A#N/AN/AN/A#N/A25-Jan-20CLOSEDN/A#N/A100COMPLETED
7207650000SITEWINAPAINT MARKER WHITE COLOR 5BOXTAUFIK ISMAIL#N/ACOMM03-Jan-20MAKSIMAN/A#N/A#N/A#N/AN/AN/A#N/A25-Jan-20CLOSEDN/A#N/A50COMPLETED
8207711101SITELIEVANOPTIC DISTRIBUTION PANEL 12 CORE 4EAYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A#REF!40COMPLETED
9207720000SITELIEVANFIBER OPTIC ARMORED UG SM 12/2T200MYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A#REF!2000COMPLETED
10207730000SITELIEVANPATCHCORD SM-SC-UPC@5MS (DUPLEX SC TO SC)4EAYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A#REF!40COMPLETED
11207740000SITELIEVANFO SM CAT MEDIA CONVERTER4EAYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A#REF!40COMPLETED
12207750000SITELIEVANFO SM SFP DUPLEX4EAYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A40COMPLETED
13207790000SITELIEVANRACKMOUNTED UPS 1000 VA APC C/W ACCSS2EAYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A20COMPLETED
142077100000SITELIEVANNYLON-TIES CABLE 20CM @100 PC/PACK10PCKYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A100COMPLETED
152077110000SITELIEVANNYLON-TIES CABLE 30CM @100 PC/PACK10PCKYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A100COMPLETED
162077120000SITELIEVANTUBE MARKER 6MM (WHITE TUBE MARKER)2ROTYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A20COMPLETED
172077130000SITELIEVANFLEXIBLE CONDUIT CLIPSAL 20 MM @100 M/ROLL20ROTYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A200COMPLETED
182077140000SITELIEVANCISCO SWITCH 2960X 24PS-L3EAYUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A11642383130983831.01.202014-Feb-20CLOSEDN/A30COMPLETED
19207811100SUBCTETIHYTERA HT RADIO NON IS TYPE15EAYUDHI PRATAMA#N/ABSMG04-Jan-20SUBCONTN/A#N/A#N/A#N/AN/AN/A#N/A12-Mar-20CLOSEDN/A150COMPLETED
20207911100SITECASH ADVANCESTAMP FOR SUBCONTRACTING1LSDHITA ROCHADICONSTCONST03-Jan-20LOCAL SUPPLIERN/A#N/A#N/A#N/AN/AN/A#N/A12-Mar-20CLOSEDN/A10COMPLETED
21208011101JAKARTARENISTICKER HSSE AWARENESS & TEP GATEWAY5,000EAIMMANUEL SUEKEN#N/AHSSE05-Jan-20REVO PRINT INDONESIAN/A#N/A#N/A#N/A11639554130809121.01.20206-Feb-20CLOSEDN/A50000COMPLETED
RFM - Register
Cells with Conditional Formatting
CellConditionCell FormatStop If True
Z:ZCell Valuecontains "IFI"textNO
Z:ZCell Valuecontains "PENDING"textNO
Z:ZCell Valuecontains "APPROVED"textNO
Z:ZCell Valuecontains "REJECTED"textNO
AA3Cell Valuecontains "REJECTED"textNO
AA3Cell Valuecontains "APPROVED"textNO
AF:AFCell Valuecontains "CANCELLED"textNO
AH11Cell Valuecontains "PENDING"textNO
AH10Cell Valuecontains "PENDING"textNO
AH9Cell Valuecontains "PENDING"textNO
AH8Cell Valuecontains "PENDING"textNO
AH7Cell Valuecontains "PENDING"textNO
AH6Cell Valuecontains "PENDING"textNO
AH5Cell Valuecontains "PENDING"textNO
AH4Cell Valuecontains "PENDING"textNO
AH3Cell Valuecontains "PENDING"textNO
AD3Cell Valuecontains "PENDING"textNO
AH1:AH2,AH12:AH1048576,AF:AFCell Valuecontains "OPEN"textNO
AH1:AH2,AH12:AH1048576,AF:AFCell Valuecontains "CLOSE"textNO
AA4:AA21Cell Valuecontains "REJECTED"textNO
AA4:AA21Cell Valuecontains "APPROVED"textNO
AE3:AF3,AE21,AA2:AF2,AH2,AB3:AC21,AE4:AE18,AH12:AH21,AF4:AF21,AD4:AD21,Y2:Y21Cell Valuecontains "PENDING"textNO
Y2Cell Valuecontains "PENDING"textNO
J:JCell ValueduplicatestextNO
 
Upvote 0
PO.xlsb
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABAC
2RFM #Material TypeRFM CountLocationBuyerDetail DescriptionRequestorDiscipline 2Discipline 1RFM Received DateRFQ Issue Date Offer Receipt DateTBE DateCBE Approval DateSelected Vendor Chargeable PartyPAMF NumberPAMF StatusPAMF Approval DatePR NumberPO NumberZJMU - PO DateZJMU - PO Amount (USD)Delivery DatePO Issuance StatusPO Under Circulation ApprovalDelivery StatusRFM MonthRFM Year
320761SITEWINAVINYL TAPE 2" 3M 471 LIGHT BLUETAUFIK ISMAIL#N/ACOMM03-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
420771SITELIEVANOPTIC DISTRIBUTION PANEL 12 CORE YUDHI PRATAMA#N/ABSMG04-Jan-20HALCOMN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
520781SUBCTETIHYTERA HT RADIO NON IS TYPEYUDHI PRATAMA#N/ABSMG04-Jan-20SUBCONTN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
620791SITECASH ADVANCESTAMP FOR SUBCONTRACTINGDHITA ROCHADICONSTCONST03-Jan-20LOCAL SUPPLIERN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
720801JAKARTARENISTICKER HSSE AWARENESS & TEP GATEWAYIMMANUEL SUEKEN#N/AHSSE05-Jan-20REVO PRINT INDONESIAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
820811SITEWINAPRESSURE GAUGERAYNAL#N/ACOMM05-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
920821SITEWINAG-SHOCK (WATCH)FERRY AYALBUSINESS MANAGEMENTCAMP06-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1020831SITEWINACOPY PAPER A4_WHITE (80GSM)JOY ANDREAN#N/ABSMG06-Jan-20DAROS SIMAN JAYAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1120841JAKARTACHANDRAPIPE HDPE PN 16. SDR 11, PE 100 PE ENDS MFG STD VINILON SIZE 8"EKO NURDIANSYAH#N/AENG07-Jan-20GLOBAL TEKNIKA UTAMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1220851JAKARTARENIHILTI ANCHOR ROD HAS-U 5.8 M10X130DONNY R.G#N/AENG07-Jan-20HILTI N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1320861SITELIEVANTEMPERATURE GAUGE ASHCROFT 250FLAWRENCE#N/AO&M08-Jan-20BINA WAHYUN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1420871SITELIEVANWELDING ROD FOR GTAW DIA 0.8MMRISMAN SBUILDINGENG08-Jan-20LESTARI KAGUNGAN MANDIRIN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1520881SITELIEVAN PIPE CLIP (DC-28-31)AGFALIA BAKAR#N/ACONST08-Jan-20LAUTAN ORGANON/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1620891SITEWINAHIGH QUALITY HEAVY DUTY RAINCOATSJOY ANDREAN#N/ABSMG09-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1720901SITEWINAALUMINIUM FLAT T GRID CEILING CHANNEL LENGTH 3 MRITESHCAMPCAMP09-Jan-20SWARNA JAYAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1820911SITEWINACEILING FAN 60 INCH HEAVY DUTYRITESHCAMPCAMP09-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
1920921SITECASH ADVANCET-SHIRT FOR FUTSAL CUPFERRY AYALBUSINESS MANAGEMENTCAMP07-Jan-20LOCAL SUPPLIERN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2020931SITEWINAELECTRIC KETTLE PHILIPS HD9306JOY ANDREAN#N/ABSMG10-Jan-20MAKSIMACPY#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2120941SITEWINAAUTOMATIC JUICE MAKER 220VRITESHCAMPCAMP10-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2220951SITEWINASCREWIMAN BUDIAWAN#N/AENG11-Jan-20MANARMAKERIN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2320961SITESUMARDIHIGH POWER LED III (BULB)SHINJI HIRAI#N/ACAMP11-Jan-20INDOMARINEN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2420971SITEWINASTEEL FILE RACKSJOY ANDREAN#N/ABSMG13-Jan-20MANARMAKERIDAEWOO#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2520981SITECASH ADVANCESTAMP LOGNANDA#N/ALOGI13-Jan-20LOCAL SUPPLIERN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2620991SITEWINAFLIP ROUND TABLEANDRY FIRZADY#N/ABSMG13-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2721001SITEWINABEST OF SUBCONT BANNERBIMANTARA#N/AHSSE13-Jan-20MAKSIMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2821011JAKARTACHANDRAFLEXIBLE HOSE TYPE 5007 SIZE ID 14" X 6.4 MFUJISAWA#N/AENG15-Jan-20GLOBAL TEKNIKA UTAMAN/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACLOSEDN/ACOMPLETEDJAN2020NO PAMF
2921021SITECANCELLED COUPLING SHAFT MAGNETIC CLUTCHSTEFAN MANAILA#N/AO&M14-Jan-20CANCELLED N/A#N/A#N/A#N/A#N/A#N/A#N/A#N/ACANCELLED N/ACANCELLEDJAN2020NO PAMF
RFM Reg
Cells with Conditional Formatting
CellConditionCell FormatStop If True
R2Cell Valuecontains "PENDING"textNO
R2Cell Valuecontains "APPROVED"textNO
R2Cell Valuecontains "REJECTED"textNO
Y2Cell Valuecontains "CANCELLED"textNO
Y2Cell Valuecontains "OPEN"textNO
Y2Cell Valuecontains "CLOSE"textNO
Q2,S2:Y2Cell Valuecontains "PENDING"textNO
Q2Cell Valuecontains "PENDING"textNO
F2Cell ValueduplicatestextNO
F2Cell ValueduplicatestextNO
 
Upvote 0
Just to be clear... What book do you want the VBA code to reside in...
 
Upvote 0
Dear igold,

The first XL2BB is the source, to copy from, and the second is the target, where I need to paste.

Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,264
Members
452,627
Latest member
KitkatToby

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