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!
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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 Lounger
Viewing 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
-
Debian 12.11 released
by
Alex5723
1 hour, 7 minutes ago -
Microsoft: Troubleshoot problems updating Windows
by
Alex5723
4 hours, 48 minutes ago -
Woman Files for Divorce After ChatGPT “Reads” Husband’s Coffee Cup
by
Alex5723
2 hours, 18 minutes ago -
Moving fwd, Win 11 Pro,, which is best? Lenovo refurb
by
Deo
1 hour, 17 minutes ago -
DBOS Advanced Network Analysis
by
Kathy Stevens
21 hours, 43 minutes ago -
Microsoft Edge Launching Automatically?
by
healeyinpa
12 hours, 8 minutes ago -
Google Chrome to block admin-level browser launches for better security
by
Alex5723
1 day ago -
iPhone SE2 Stolen Device Protection
by
Rick Corbett
16 hours, 39 minutes ago -
Some advice for managing my wireless internet gateway
by
LHiggins
12 minutes ago -
NO POWER IN KEYBOARD OR MOUSE
by
HE48AEEXX77WEN4Edbtm
18 hours, 36 minutes ago -
A CVE-MITRE-CISA-CNA Extravaganza
by
Nibbled To Death By Ducks
1 day, 9 hours ago -
Sometimes I wonder about these bots
by
Susan Bradley
1 day, 6 hours ago -
Does windows update component store “self heal”?
by
Mike Cross
20 hours, 13 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
1 day, 23 hours ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
7 hours, 47 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
11 hours, 28 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
2 days, 2 hours ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
2 days, 2 hours ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
1 day, 15 hours ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
2 days, 10 hours ago -
0Patch, where to begin
by
cassel23
2 days, 4 hours ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
3 days ago -
89 million Steam account details just got leaked,
by
Alex5723
2 days, 12 hours ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
3 days, 8 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
2 days, 23 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
2 hours, 2 minutes ago -
Installer program can’t read my registry
by
Peobody
1 hour, 35 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
2 days, 21 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
3 days, 4 hours ago -
False error message from eMClient
by
WSSebastian42
3 days, 20 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.