Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sorting By Largest Value In A String

I would like to find the largest value, in a string of values in a
cell. The, using that information, i would like to sort the rows in a
worksheet by that largest value.

A representative cell contains characters like this:

141, 141, 130, 130, 108 and 108

For instance, I woulld like for it to say 141 is the largest value.
Then, it should sort the rows containing these cells by that largest
value.

Can anyone give me a function, or program, that would allow me to do
this?

Thanks,
Alan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Sorting By Largest Value In A String

use a helper column

Create a function like
Public Function BiggestNumber(rng As Range) As Variant
Dim s As String, v As Variant
Dim i As Long, Max As Long
If rng.Count 1 Then
BiggestNumber = CVErr(xlErrRef)
Exit Function
End If
s = LCase(rng.Text)
s = Replace(s, " and ", ",")
s = Replace(s, " ", "")
v = Split(s, ",")
Max = -10000
For i = LBound(v) To UBound(v)

If IsNumeric(v(i)) Then
If CLng(v(i)) Max Then _
Max = CLng(v(i))
End If
Next
BiggestNumber = CDbl(Max)
End Function

Put it in a general module (not a sheet module or the thisworkbook module)

(assume the string of numbers is in column B)
then in another cell in the same row put in a formula like

=BiggestNumber(B1)

then drag fill down the column

Now sort with this helper column as the Key field.

--
Regards,
Tom Ogilvy





" wrote:

I would like to find the largest value, in a string of values in a
cell. The, using that information, i would like to sort the rows in a
worksheet by that largest value.

A representative cell contains characters like this:

141, 141, 130, 130, 108 and 108

For instance, I woulld like for it to say 141 is the largest value.
Then, it should sort the rows containing these cells by that largest
value.

Can anyone give me a function, or program, that would allow me to do
this?

Thanks,
Alan


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting cells with a string formulas Erik Excel Worksheet Functions 1 February 6th 10 11:15 PM
sorting by sector and find largest 3 number each macro help needed barkiny[_3_] Excel Programming 3 October 7th 05 11:18 PM
Largest Value o5prey Excel Worksheet Functions 5 June 20th 05 06:46 PM
string sorting problem NikkoW Excel Programming 1 May 2nd 04 04:59 PM
sorting data in string Mark[_17_] Excel Programming 1 September 16th 03 05:08 PM


All times are GMT +1. The time now is 07:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"