Excel code runs very slowly

09Tina

New Member
Joined
Dec 16, 2019
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a code that excel runs very slowly (about 3 or 4 minutes) and i don't know what the problem is. I tried with option to put calculation on manually but it's not helpful at all, I also tried put it into a code, it didn't worked. Please help!
My code:
Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)

 Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
 Dim WS As Worksheet
Set WS = Sheets("Sheet1")
With WS
    .Unprotect Password:="0000"
    .UsedRange.Locked = True
    .UsedRange.SpecialCells(xlCellTypeBlanks).Locked = False
    .Protect Password:="0000"
End With

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Exit Sub

End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Maybe try this
VBA Code:
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim WS As Worksheet
    Set WS = Sheets("Sheet1")
    With WS
        .Unprotect Password:="0000"
        .UsedRange.Locked = True
        .UsedRange.SpecialCells(xlCellTypeBlanks).Locked = False
        .Protect Password:="0000"
    End With
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
If you select cell A1 on sheet1 & use Ctrl End, where do you end up?
 
Upvote 0
I would also suggest deleting all the rows below the last row data may well speed other things up as well & reduce the size of the file.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

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