PDA

View Full Version : Trouble sorting as part of a Macro



MichaelB
10-27-2020, 03:14 PM
Hello, So I found some code that does the sorting that I want but when I try to run the Function as part of a macro the sorting does not work. Through a google search I found this code:


Sub Sortmybin()
Range("f2").CurrentRegion.Sort _
Key1:=Range("f2").CurrentRegion.Sort _
Order1:=XLDescending, _
Header:=XLyes


End Sub

but I am getting a compile error for Expected end of Statement on the Order1 line.

Any ideas?

Thank you.

Bob Phillips
10-27-2020, 03:40 PM
Shouldn't it be


Sub Sortmybin()
Range("F2").CurrentRegion.Sort _
Key1:=Range("F2"), _
Order1:=xlDescending, _
Header:=xlYes
End Sub

MichaelB
10-27-2020, 03:47 PM
Yes sir that compiled. Now to see if it does what I am hoping. This is my first time using this forum. Do I owe you for your help?

Bob Phillips
10-27-2020, 03:57 PM
Yes of course you owe me, I'll be round to your house for a beer, once life allows such things again :(

MichaelB
10-28-2020, 09:06 AM
Yes of course you owe me, I'll be round to your house for a beer, once life allows such things again :(


Haha, you're on. Thank you very much.

If I can't figure out:banghead: how to do the little project I am working on would you be interested? But if it goes that route I insist in paying you more than some beers:yes

Bob Phillips
10-28-2020, 12:59 PM
If you do struggle, just PM me and I will check whether it warrants a gig, or whether it is just something to be addressed here on the forum (determined by the complexity).