Problem with ActiveSheet.Paste function

Copper Contributor

Hello All,

I used for a long time a small code into a worksheet to avoid doing manual Copy/Paste.
Since 2019 this code worked well until yesterday. This is te part of my code where the problem happend.

 

 

If ind > 5 Then 'Pour éviter de copier l'entête du tableau
splagePrec = "A" + Trim(CStr(ind - 1)) & ":M" & Trim(CStr(ind - 1))
Range(splagePrec).Select
Selection.Copy
splage = "A" + Trim(CStr(ind))
Range(splage).Select
ActiveSheet.Paste
End If

 

 

Each part of this code run correctly until the instruction ActiveSheet.Paste.
It can take 15 min to execute this simple line.
I have tested on Windows 11/Excel 2019 PC and on Windows 10/Excel 2016 PC. the result is similar.
I don't understand why this problem start now
thank you for any help

6 Replies

@cheickhamala 

I don't know why it takes so long, but see if this works better:

 

    If ind > 5 Then 'Pour éviter de copier l'entête du tableau
        Range("A" & ind - 1 & ":M" & ind - 1).Copy Destination:=Range("A" & ind)
    End If

@Hans Vogelaar 

Your code is very simple! Thank you for that.

I tested it but the result is similar. So, maybe the problem isn't ActiveSheet.Paste function.

 

@cheickhamala 

Try adding the following lines at the beginning of your macro:

 

    Application.Cursor = xlWait
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False

 

and at the end:

 

    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    Application.Cursor = xlDefault

 

I replaced ":=" by "=" for this line Application.Calculation:=xlCalculationManual because of an error.
The cursor change at this previous line but when the copy and paste line is executed it continues to take longer

@cheickhamala 

My apologies for the error; I have corrected it.

I'm afraid I have no further suggestions without seeing the workbook.

Thank's for what you did. I learnt the simplest way to write this code