VBA sort code no longer working

jaclwb

New member
Joined
Aug 24, 2021
Messages
6
Reaction score
0
Points
0
Excel Version(s)
2016
I have a sheet with four columns (Company, Activity, People, Date) and I'm trying to have the document automatically sort by date whenever a new activity & date is entered.

I'd set up a VBA sort code to automatically sort information using this code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    Range("D1").Sort Key1:=Range("D45"), _
      Order1:=xlAscending, Header:=xlYes, _
      OrderCustom:=1, MatchCase:=False, _
      Orientation:=xlTopToBottom
End Sub
It worked perfectly when I first set it up and tested it. I saved the document and when I opened it this morning it's no longer automatically sorting when I enter new dates or change existing dates. I don't know what's happening. Please help!
 
Last edited by a moderator:
Is cell D2 blank?
Best attach a workbook with it not working.
 
Is cell D2 blank?
Best attach a workbook with it not working.

No, D2 has a date entered. I've attached the workbook where it's not working.
 

Attachments

  • BK Marketing Activity Tracker.xlsm
    15.4 KB · Views: 10
Works here.
1. Is it on SharePoint?
2. If you type:
?application.EnableEvents
in the Immediate pane of the VBE then press Enter what does it return with?
 
Works here.
1. Is it on SharePoint?
2. If you type:
?application.EnableEvents
in the Immediate pane of the VBE then press Enter what does it return with?

It's not on SharePoint.

I tried typing in the line as you suggested, but nothing changed. I went back into the worksheet and changed a date and it didn't re-sort. I tried adding a date and it didn't re-sort. It had worked for me yesterday when I first created the document so I'm stumped as to why it's not sorting for me now.
 
I tried typing in the line as you suggested, but nothing changed.
It won't change anything, it should return True or False in the Immediate Pane as soon as you press Enter. I want to know if it says True or False. Note: it starts with a question mark.
 
It won't change anything, it should return True or False in the Immediate Pane as soon as you press Enter. I want to know if it says True or False. Note: it starts with a question mark.

It doesn't say True or False. When I type it in and press enter it turns into: Print Application.EnableEvents
 
It doesn't say True or False. When I type it in and press enter it turns into: Print Application.EnableEvents
Then you're not typing it in the Immediate pane (more probably where the rest of the code is), bring the Immediate pane up by Ctrl +g on the keyboard.
 
Last edited:
Then you're not typing it in the Immediate pane (more probably where the rest of the code is), bring the Immediate pane up by Ctrl +g on the keyboard.

I get a pop-up saying the macros in this project are disabled.
 
I get a pop-up saying the macros in this project are disabled.

Then that's why!
Close the workbook, re-open it while enabling macros.
 
Then that's why!
Close the workbook, re-open it while enabling macros.

Thanks - I figured out how to re-set my macros setting so now I can enable it each time I open the document. Thanks for all your help!
 
Back
Top