Private Sub keeps freezing file

BrainDiseasee

New Member
Joined
Aug 30, 2023
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello, i have a code that is displaying the last changed cell of a range. It works for a few tests but then randomly will freeze up my workbook. Any help would be great, also im looking to make this apply to all worksheets in the workbook, if anyone has any direction on that it would be helpful as i am lost on how to make a privae sub work as a public sub/function.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("A1:A10")
Application.EnableEvents = False
If Not Intersect(Target, Range("E5:E15")) Is Nothing Then


Range("J39") = Target.Address
Application.EnableEvents = True
End If

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
If you place this code in the "ThisWorkbook" module, it will apply to ALL sheets in your workbook:
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    If Not Intersect(Target, Sh.Range("E5:E15")) Is Nothing Then
        Application.EnableEvents = False
        Sh.Range("J39") = Target.Address
        Application.EnableEvents = True
    End If

End Sub
 
Upvote 0
Solution
If you place this code in the "ThisWorkbook" module, it will apply to ALL sheets in your workbook:
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    If Not Intersect(Target, Sh.Range("E5:E15")) Is Nothing Then
        Application.EnableEvents = False
        Sh.Range("J39") = Target.Address
        Application.EnableEvents = True
    End If

End Sub
That definitely solved the issue of getting to work on multiple sheets. However still having an issue with it crashing. My plan is to have a drop list from data validation, so when i go to my main sheet and try this it freezes up where i can t click on anything
 
Upvote 0
That definitely solved the issue of getting to work on multiple sheets. However still having an issue with it crashing. My plan is to have a drop list from data validation, so when i go to my main sheet and try this it freezes up where i can t click on anything
Disregard the freezing is something with in the actual drop list or something else because I disabled the code and it still froze. Thanks again!!!
 
Upvote 0
You are welcome.

Yeah, I was going to say that there isn’t really anything in that code that would cause it to crash, especially since we are disabling events while the update happens.
 
Upvote 0

Forum statistics

Threads
1,215,077
Messages
6,122,992
Members
449,094
Latest member
masterms

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