Is there any way to write a macro that would tell XL to just sort by the last column of the current selection, largest to smallest?I do get so fed up with having to set up the sort, telling it which column and changing to largest to smallest every time when we have literally dozens of selections to do this to …!Any help would be gratefully and greatly appreciated!
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
How to do a last column sort?
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » How to do a last column sort?
- This topic has 7 replies, 2 voices, and was last updated 13 years, 2 months ago.
Viewing 2 reply threadsAuthorReplies-
WSBerylM
AskWoody LoungerMarch 2, 2012 at 2:22 am #1322859I keep trying to edit the above post to make my request clearer, but it won’t accept any changes, so herewith the altered version separately: “Is there any way to write a macro that would tell XL to just sort by the last column of the current selection (ie far right column, whether fourth of four, eighth of eight, or whatever), and largest to smallest? I do get so fed up with having to set up the sort, telling it which column and changing to largest to smallest every time when we have literally dozens of selections to do this to …! Any help would be gratefully and greatly appreciated!”
-
zeddy
AskWoody_MVPMarch 2, 2012 at 4:41 am #1322874Hi Beryl
This could be done with VBA but do you need to?
If you are using Excel2003(?) you could simply add the Descending Sort icon to your toolbar.
That way, when you have a currentRegion block of data, you simply put the cellpointer in the column you want sorted and click the descending-sort icon.If you want a VBA solution, post a reply and let us know which Excel version you are using.
zeddy
-
WSBerylM
AskWoody LoungerMarch 5, 2012 at 3:58 am #1323294Thank you, Zeddy, I think that will do what I want! One question, though – how do you “put the cellpointer in the column you want sorted”? I did it by starting the selection in that column (which for my purposes at this moment, sorting always on the last column, works fine) but what if I was selecting several columns and I wanted to sort by one of the middle ones – how do I put the cell pointer in that column? When I try I just lose the selection! By the way, how does one put a blank line in one of these posts now?!! You used to just press return twice as per a wordprocessor, but I notice that it now runs them together (as you’ll probably see with this para, which will no doubt run into the previous one even though I’ve put returns between them!Thanks again!
-
zeddy
AskWoody_MVPMarch 5, 2012 at 9:29 am #1323317Hi Beryl
If you are only sorting on ONE column (as per your first post), then you just need the cellpointer on a data cell anywhere in that column (e.g. on the column header preferably). The sort will then ‘grab’ the current region around that selected cell and do the sort.
If you want to sort on more than one column at the same time (e.g. sort this column first then this column etc) then you have to use the Data Sort option from the top-panel command bar. The cellpointer can be anywhere in the data block to be sorted. When you select Data and then Sort, the current region is selected automatically and you will see the sort options dialog sheet. This dialog sheet allows you to specify the order of your sorts (i.e. which data columns) and sort type, for up to three columns.
Re: how does one put a blank line in one of these posts now?!!p
As you stated, I press return twice as per a wordprocessor.
Works for me!zeddy
-
WSBerylM
AskWoody LoungerMarch 6, 2012 at 2:14 am #1323431Hi Zeddy, slight misunderstanding here – I need to be able to select a block of cells, several columns by several rows – which will not necessarily be the current region as we have columns of formulae to the right of the data cells that are not to be touched by the sort – then sort by just one column within that block. Re putting blank lines, mine simply doesn’t, as you can see from the earlier posts (and probably this one) – I’ve been trying to remember to put spaces at the end of the paras so when it runs them together it doesn’t do so quite literally, but I’d much rather they stayed as separate paras! Thanks for your help.
-
zeddy
AskWoody_MVPMarch 6, 2012 at 5:46 am #1323467Hi Beryl
Well I suppose I had better answer your first post exactly as you require.
It’s just that I think sorting a ‘selected’ range (rather than a ‘current region’) can often do more harm than good.
Sorting any block of data, particularly when the selected ‘block’ lies within another ‘block’, can often ‘mess up’ data records.
But never mind that, here is a VBA routine that will specifically sort the last column of a selected range in descending order. You could assign this routine to a ‘custom button’ in your toolbar:Code:Sub sortSelectionLastColumn() If Selection.Rows.Count = 1 Then Exit Sub If Selection.Cells.Count = 1 Then Exit Sub zLastCell = Selection.Find(What:="*", _ SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious).Address Selection.Sort Key1:=Range(zLastCell), Order1:=xlDescending, Header:=xlGuess End Sub
zeddy
-
-
-
-
WSBerylM
AskWoody LoungerViewing 2 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Office gets current release
by
Susan Bradley
50 minutes ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
6 hours, 13 minutes ago -
Windows AI Local Only no NPU required!
by
RetiredGeek
2 hours, 57 minutes ago -
Stop the OneDrive defaults
by
CWBillow
7 hours, 1 minute ago -
Windows 11 Insider Preview build 27868 released to Canary
by
joep517
16 hours, 57 minutes ago -
X Suspends Encrypted DMs
by
Alex5723
19 hours, 9 minutes ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
19 hours, 27 minutes ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
20 hours, 4 minutes ago -
OpenAI model sabotages shutdown code
by
Cybertooth
20 hours, 41 minutes ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
8 hours, 51 minutes ago -
Enabling Secureboot
by
ITguy
15 hours, 51 minutes ago -
Windows hosting exposes additional bugs
by
Susan Bradley
1 day, 4 hours ago -
No more rounded corners??
by
CWBillow
1 day ago -
Android 15 and IPV6
by
Win7and10
14 hours, 9 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
1 day, 16 hours ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
1 day, 19 hours ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
1 day, 14 hours ago -
Windows Update orchestration platform to update all software
by
Alex5723
2 days, 2 hours ago -
May preview updates
by
Susan Bradley
1 day, 14 hours ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
1 day, 5 hours ago -
Just got this pop-up page while browsing
by
Alex5723
1 day, 19 hours ago -
KB5058379 / KB 5061768 Failures
by
crown
1 day, 16 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
18 hours, 24 minutes ago -
At last – installation of 24H2
by
Botswana12
2 days, 18 hours ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
15 hours, 11 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
3 days, 6 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
1 day, 5 hours ago -
Limited account permission error related to Windows Update
by
gtd12345
3 days, 20 hours ago -
Another test post
by
gtd12345
3 days, 20 hours ago -
Connect to someone else computer
by
wadeer
3 days, 14 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.