Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-30-2021, 09:51 PM
ganesang ganesang is offline Need to sort based on the length of cells Windows XP Need to sort based on the length of cells Office 2016
Competent Performer
Need to sort based on the length of cells
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default Need to sort based on the length of cells

Hi Guys



I need to sort data in column A ranges A2:end of value based on their length using excel macro.

I have attached my file to sort column A.

Can anyone help out on this?

I have used this function but i need to add this as macro: SORTBY(A2:A36,LEN(A2:A36),-1)

thanks
Attached Files
File Type: xlsm Source1.xlsm (15.7 KB, 8 views)
Reply With Quote
  #2  
Old 08-31-2021, 11:50 AM
p45cal's Avatar
p45cal p45cal is offline Need to sort based on the length of cells Windows 10 Need to sort based on the length of cells Office 2019
Expert
 
Join Date: Apr 2014
Posts: 863
p45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant future
Default

Try:
Code:
Sub blah()
'Set rngToSort = Range("A2:A36")
'Set rngToSort = Selection
Set rngToSort = Range(Cells(2, "A"), Cells(Rows.Count, "A").End(xlUp))
rngToSort.Value = Application.SortBy(rngToSort, Evaluate("LEN(" & rngToSort.Address(external:=True) & ")"), -1)
End Sub
Set rngToSort any way you like - a few examples at the top of the macro. Apart from that it's a one-liner.
Reply With Quote
  #3  
Old 08-31-2021, 09:58 PM
ganesang ganesang is offline Need to sort based on the length of cells Windows XP Need to sort based on the length of cells Office 2016
Competent Performer
Need to sort based on the length of cells
 
Join Date: Jul 2018
Posts: 171
ganesang is on a distinguished road
Default

Thanks so much!

Works perfectly!!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort pages based on header comphi Word VBA 0 09-22-2018 11:14 PM
Conditional formating all cells in an array based on adjacent cells deejay Excel 6 12-20-2016 12:00 PM
Need to sort based on the length of cells How to add new pages based on the length of a TOC? gn4619 Word VBA 2 04-28-2015 06:37 AM
Is it possible to sort cells in shades of colors? Kreol2013 Excel Programming 9 02-09-2014 02:38 PM
Need to sort based on the length of cells How to Sort Table Cells from Left to Right tamaracklodge Word Tables 4 03-04-2013 04:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft