To Macro or use Small with VSLookup.

philipt

New member
Joined
Apr 2, 2013
Messages
1
Reaction score
0
Points
0
I have a page that I have written a macro for and works great on my computer, but makes their excel stall. I think I can accomplish the same results without using a macro. My goal is to have column J sorted automatically after data is changed. I have a link to the excel document below but my macro is:

Private Sub Worksheet_Calculate()
Set Target = Sheet3.Range("A5:J29").SpecialCells(xlCellTypeFormulas)
Range("A5:J29").Sort _
Key1:=Range("J6"), _
Order1:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub

Is there something wrong with this macro? Otherwise, Can someone recommend a way to have it sort by the Market Basket Average in my page. Perhaps using the Small or Large code. I was using =VLOOKUP($J6,'Data Table'!A2:J25,COLUMN(A1),FALSE) and made a data table on a sheet to hide, but I always got an #NA error.

(Looks like they won't let me post a link yet, so if you can help, PM me and I will send you the URL)

Thanks,
Phil
 

NoS

New member
Joined
Jan 17, 2013
Messages
832
Reaction score
0
Points
0
Location
British Columbia
Excel Version(s)
Excel 2010
Suspect different versions of Excel on different computers. If possible try constructing the macro on the other computer and I'd bet it will then work on both.
 

JoePublic

Super Moderator
Staff member
Joined
Sep 16, 2011
Messages
223
Reaction score
2
Points
18
Location
UK
Excel Version(s)
2016
Perhaps you just need to disable events (not real sure why you bother with Target since you don't use it)
Code:
[COLOR=#333333][COLOR=#333333]Private Sub Worksheet_Calculate()[/COLOR][/COLOR]
[COLOR=#333333]application.enableevents = false[/COLOR]
[COLOR=#333333][COLOR=#333333]Range("A5:J29").Sort _[/COLOR][/COLOR]
[COLOR=#333333][COLOR=#333333]Key1:=Range("J6"), _[/COLOR][/COLOR]
[COLOR=#333333][COLOR=#333333]Order1:=xlAscending, _[/COLOR][/COLOR]
[COLOR=#333333][COLOR=#333333]Header:=xlYes, _[/COLOR][/COLOR]
[COLOR=#333333][COLOR=#333333]OrderCustom:=1, _[/COLOR][/COLOR]
[COLOR=#333333][COLOR=#333333]MatchCase:=False, _[/COLOR][/COLOR]
[COLOR=#333333][COLOR=#333333]Orientation:=xlTopToBottom, _[/COLOR][/COLOR]
[COLOR=#333333][COLOR=#333333]DataOption1:=xlSortNormal
[/COLOR][/COLOR]application.enableevents = true
[COLOR=#333333][COLOR=#333333]End Sub
[/COLOR][/COLOR]
 

JoePublic

Super Moderator
Staff member
Joined
Sep 16, 2011
Messages
223
Reaction score
2
Points
18
Location
UK
Excel Version(s)
2016
Read the footnote ;)
 

NoS

New member
Joined
Jan 17, 2013
Messages
832
Reaction score
0
Points
0
Location
British Columbia
Excel Version(s)
Excel 2010
WOW, you should work for our local City Council. That's a fantastic job of deception.
 
Top