VBA Macros running slow out of nowhere

Jeff2554

New Member
Joined
Mar 5, 2024
Messages
5
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello all,
I'm hoping someone can take a peak at my file and see if they can figure out why the macros are running so slow.
When I originally built the workbook, the macros would execute in less than a second. Out of nowhere, they slowed way down and are prone to crash.
The first time this happened, I went to an older save and rebuilt the whole file which then fixed the issue and I had two separate saves that worked great.
Much to my dismay when I came back to work on Monday, they both run super slow and/or crash with no errors.
The code is not super complex, and when I step through the macros it seems to get stuck on operations like inserting cells, copying, and pasting.
I also have each sheet locked into only one selection to prevent things from being selected and potentially having formulas get broken.
Hence the application.EnableEvents at the beginning and end of the macros.

VBA Code:
Sub SendIt()

Dim rng As Range
Dim cell As Range
Dim search As String
Dim lane As String
Dim dist As String

Application.EnableEvents = False

If ThisWorkbook.Sheets("Main Sheet").Range("B11") = "Enter Part" Then
    MsgBox "Please enter a valid part number, thanks."
    ThisWorkbook.Sheets("Main Sheet").Range("B6").Select
    Selection.ClearContents
    Application.EnableEvents = True
    Exit Sub
End If

On Error Resume Next
    ThisWorkbook.Sheets("Log").ShowAllData
On Error GoTo 0

'Log Information
Call Log_Improved

Set rng = ThisWorkbook.Sheets("Lanes").Columns("D:D")
search = ThisWorkbook.Sheets("Main Sheet").Range("B6")
Set cell = rng.Find(What:=search, LookIn:=xlFormulas, LookAt:=xlWhole, MatchCase:=False)

Worksheets("Lanes").Activate
cell.Select
lane = ActiveCell.Offset(0, -2)
cell.Select
dist = ActiveCell.Offset(0, -1)


'Set Range of Lane the part goes to

Worksheets("Lanes").Activate
cell.Select
ActiveCell.Offset(0, dist) = ActiveCell.Offset(o, dist) + 1

Worksheets("Main Sheet").Activate
ThisWorkbook.Sheets("Main Sheet").Range("B6").ClearContents

Application.EnableEvents = True

End Sub

Sub Log_Improved()

    Dim P As Range
    Dim L As Range
    Dim T As Range
    Dim D As Range
    
    Set P = ThisWorkbook.Sheets("Log").Range("L3")
    Set L = ThisWorkbook.Sheets("Log").Range("L4")
    Set T = ThisWorkbook.Sheets("Log").Range("L5")
    Set D = ThisWorkbook.Sheets("Log").Range("L6")
    
    ThisWorkbook.Sheets("Log").Range("E8:H8").Insert Shift:=xlDown
    ThisWorkbook.Sheets("Log").Range("M3:M6").Insert Shift:=xlToRight

    ThisWorkbook.Sheets("Log").Range("E8") = P
    ThisWorkbook.Sheets("Log").Range("F8") = L
    ThisWorkbook.Sheets("Log").Range("G8") = T
    ThisWorkbook.Sheets("Log").Range("H8") = D

    ThisWorkbook.Sheets("Log").Range("M3") = P
    ThisWorkbook.Sheets("Log").Range("M4") = L
    ThisWorkbook.Sheets("Log").Range("M5") = T
    ThisWorkbook.Sheets("Log").Range("M6") = D
    
    ThisWorkbook.Sheets("Main Sheet").Range("H2:H5").Insert Shift:=xlToRight
    
    ThisWorkbook.Sheets("Main Sheet").Range("H2") = P
    ThisWorkbook.Sheets("Main Sheet").Range("H3") = L
    ThisWorkbook.Sheets("Main Sheet").Range("H4") = T
    ThisWorkbook.Sheets("Main Sheet").Range("H5") = D
    
End Sub

Sub Clear()
'
' Clear Macro
'
Application.EnableEvents = False
'Move Stock
    Range("NHKStock").Copy ThisWorkbook.Sheets("Lanes").Range("AI4")

'Move Leftmost Lane
    Range("NHKLeftmost").Copy ThisWorkbook.Sheets("Lanes").Range("AF3")

'Reformat
    Range("AllNHKLanes").Copy ThisWorkbook.Sheets("Lanes").Range("E3")

'Change next load number
    ThisWorkbook.Sheets("Lanes").Range("AC4") = ThisWorkbook.Sheets("Lanes").Range("Z4") + 1
    
'Clear Current from moved lane
    ThisWorkbook.Sheets("Lanes").Range("AD7:AD37").ClearContents
    
'Clear Load from Pullsheet
    ThisWorkbook.Sheets("Pullsheet Drop").Range("D1:D34").Delete
    
Application.EnableEvents = True
    
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
it seems to get stuck on operations like inserting cells, copying, and pasting.
Sometimes when a worksheet gets very large, those kinds of operations slow down.

Also if there is a corporate IT department in the mix pushing updates to your PC, what they do can sometimes have a big effect. If the real-time AV scanner becomes interested in what Excel is doing, that can slow things down- something I have experienced myself. You can usually tell if something like this is going on by launching Task Manager, then sorting the process window by CPU usage.
 
Upvote 0
If you have a large number of formulae in you workbook, they can slow things down if they are constantly re-calculating. Your code can be revised to make it more efficient. I think that it would be easier to help and test possible solutions if we could work with your actual file which includes any macros you are currently using. Perhaps you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. Include a detailed explanation of what you would like to do using a few examples from your data and referring to specific cells, rows, columns and worksheets. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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