Rijnsent
Well-known Member
- Joined
- Oct 17, 2005
- Messages
- 1,483
- Office Version
- 365
- Platform
- 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):
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?
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
- 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?