Macro Slowing Work Book

rv79

New Member
Joined
Apr 20, 2011
Messages
5
Hi Guys

I desperatley require help with the following, i have a work book that i use as a database for work requests that is kept on a server which other people can log job requests on, basically the vba code that i have created seems to slow the work book right down which is making it practically impossible to log jobs?

Here is the macro EventProc1 creates a time stamp, EventProc2 sorts column J

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False

EventProc1 Target
EventProc2 Target

Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Private Sub EventProc1(ByVal Target As Range)
If Target.Column = 10 Then
Application.EnableEvents = False
Cells(Target.Row, 11).Value = Date + Time
Application.EnableEvents = True
End If
End Sub

Private Sub EventProc2(ByVal Target As Range)
Dim LR As Long
If Target.Column <> 10 Then Exit Sub
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("A1:N" & LR).Sort Key1:=Range("J2"), Order1:=xlDescending, _
Header:=xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub



Any help with this would be greatly appricated?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi there,

Several observations:

When posting code, use the [code=rich] ...your code pasted here [/code] tags and some sort of indentation. It makes the code a lot easier to read, for both any helper and you.

Rich (BB code):
Option Explicit
    
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
    EventProc1 Target
    EventProc2 Target
    
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
    
Private Sub EventProc1(ByVal Target As Range)
    If Target.Column = 10 Then
        Application.EnableEvents = False
        Cells(Target.Row, 11).Value = Date + Time
        Application.EnableEvents = True
    End If
End Sub
    
Private Sub EventProc2(ByVal Target As Range)
Dim LR As Long
    
    If Target.Column <> 10 Then Exit Sub
    
    LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    
    Range("A1:N" & LR).Sort Key1:=Range("J2"), _
                            Order1:=xlDescending, _
                            Header:=xlYes, _
                            OrderCustom:=1, _
                            MatchCase:=False, _
                            Orientation:=xlTopToBottom
End Sub

A minor point: You are disabling/re-enabling events twice when only once appears needed.

I suspect more at root of speed issue: Yare searching the the entire sheet. Search (at max) the column we have Change triggering on.
 
Upvote 0

Forum statistics

Threads
1,225,157
Messages
6,183,248
Members
453,152
Latest member
ChrisMd

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