VBA Worksheet_Change Help (might be a simple thing)

chooch147

New Member
Joined
Mar 25, 2005
Messages
12
I'm not a VBA or Excel expert, but I thought the code below was pretty simple. It basically sorts a range of cells everytime a value on the sheet changes. It worked perfectly in Excel 2003, but in Excel 2007 nothing happens. Does anyone have any idea if there is an incompatibility, or maybe something in 2007 that I need to enable for this to work?

Private Sub Worksheet_Change(ByVal Target As Range)
With Worksheets("LeaderBoard")
.Range("C4:E28").Sort Key1:=.Range("D4"), Order1:=xlDescending, Key2:=.Range("E4"), Order2:=xlDescending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Range("H4:J28").Sort Key1:=.Range("I4"), Order1:=xlDescending, Key2:=.Range("J4"), Order2:=xlDescending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End With
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
It should be backwards compatible, but you might want to try recording the sort in 2007 and replacing the resulting code.
 
Upvote 0
It works for me in both Excel 2002 and Excel 2007. Two things for you to check:

1. When you open the workbook in Excel 2007, you will need to ensure macros are enabled. Depends on your macro security settings, but when you open the workbook have look just above the formula bar for a 'Security Warning'. If it is there, you will need to click 'Options...' and choose 'Enable this content'

2. If the above doesn't fix the problem, you also need to ensure that your vba 'Events' have not been disabled. In the VB window, ensure the Immediate Window is visible (View|Immediate Window) and then on a new line in the Immediate Window, type
Application.EnableEvents=True and press Enter
 
Upvote 0
Smitty...thanks for the advice. I tried that but it didn't work.

Peter -- you were dead on. I already had macros enabled, but did not have the VBA Events enabled. Like I said in the post, I am FAR from an expert so I had no idea where to look for this.
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,301
Members
448,885
Latest member
LokiSonic

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