Macro speed - copy/paste rows

Rijnsent

Well-known Member
Joined
Oct 17, 2005
Messages
1,483
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I'm working on a macro where I have to swap around some rows on a sheet. So I've added some grouping labels in column B, loop though my 150 rows and move blocks in a certain order. Moving means: cut and paste at the top. Roughly speaking, this is what I'm doing (option Explicit is on):
VBA Code:
    Dim Sht As Worksheet
    Dim Rw As Long, StartRw As Long, EndRw As Long, MoveAction As Integer, MoveBlock As Integer, i As Integer
    Dim CopyRwStart As Long, CopyRwEnd As Long, PasteRw As Long

' in a loop, determine the start- and endrow, next,
    Set Sht = Worksheets("MY_SHEET")
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlCalculationManual
    For i = 1 to 10
         'Do something to determine the start- and endrow and pasterow - blocks are max 10 rows, and the total range everything happens in is 150 rows.
         Sht.rows(CopyRwStart & ":" & CopyRwEnd).Cut
        Sht.Cells(PasteRw, 1).rows("1:1").EntireRow.Insert shift:=xlDown
        Application.CutCopyMode = False
    next i
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.Calculation = xlSemiAutomatic
In my macro, there are about 10 of those cut-paste actions (want to move some rows up). The main issues I currently bump into:
- when timing the macro, each cut-paste action takes almost a second, which feels way too long. At my colleagues PC, each cut-paste action takes almost 5 seconds. - so on my PC the total macro runs for 10 seconds, on his almost a minute :-(.
- sometimes, a clipboard-warning pops up (guess Windows native), throwing a warning (not stopping the process).

Does anyone here know a solution to speed this up? And does anyone know if I can in VBA somehow avoid that pesky clipboard warning popping up?
 

Forum statistics

Threads
1,226,812
Messages
6,193,114
Members
453,777
Latest member
Miceal Powell

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