Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Comparing Values for Sorting

Dear Colleagues;

How do I sort an array containing the following string values?

I tried using Strcmp function and < comparison to compare each elements,
but the results don't look as I expected. for example if I compare 030814-01
with 030811-02, Strcomp renders a reverse result. But when I paste this
value into a sheet the Sort works ok. So, I'm lost.

Any guidances will be most appreciated.


from this

030814-01
030409-01-R1
030821-01
030731-01
030821-02
030613-01
030613-01R1
030821-02R1
030811-01R1
030823-01
030811-02

to this

030409-01-R1
030613-01
030613-01R1
030731-01
030811-01R1
030811-02
030814-01
030821-01
030821-02
030821-02R1
030823-01

Suk Ho


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Comparing Values for Sorting

I pasted in your data:

030613-01 ' in cell A1
030613-01R1 ' in cell A2
030731-01
030811-01R1
030811-02
030814-01
030821-01
030821-02
030821-02R1
030823-01


and in the cell next to each I put in a UDF

Function CompStr(rng As Range, rng1 As Range)
CompStr = StrComp(rng, rng1, vbTextCompare)
End Function

starting in B1 so that the formula in B1 was

=Compstr(A1,A2)

In each case, the formula returned -1 indicating that the value in that row
was less than the value in the next row - so that string compare was/is
returning the same evaluation as the Sort command.

It is unclear how you are using strcomp, but I would suggest your code is
misinterpreting what is returned.

--
Regards,
Tom Ogilvy



Suh, Suk Ho wrote in message
news:rNizjIXaDHA.274@newsgroup...
Dear Colleagues;

How do I sort an array containing the following string values?

I tried using Strcmp function and < comparison to compare each elements,
but the results don't look as I expected. for example if I compare

030814-01
with 030811-02, Strcomp renders a reverse result. But when I paste this
value into a sheet the Sort works ok. So, I'm lost.

Any guidances will be most appreciated.


from this

030814-01
030409-01-R1
030821-01
030731-01
030821-02
030613-01
030613-01R1
030821-02R1
030811-01R1
030823-01
030811-02

to this

030409-01-R1
030613-01
030613-01R1
030731-01
030811-01R1
030811-02
030814-01
030821-01
030821-02
030821-02R1
030823-01

Suk Ho




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
Comparing values in columns Sandy Excel Worksheet Functions 2 April 19th 07 09:40 AM
Help with Comparing values and retrieving values in Excel!!!!!! [email protected] Excel Worksheet Functions 1 November 17th 06 12:21 AM
Comparing values between columns only when there are values in bot Mark K Excel Worksheet Functions 1 February 19th 06 06:47 PM
Comparing values Dirk_Bob Excel Discussion (Misc queries) 2 August 24th 05 09:39 PM
comparing two values Jerry Excel Worksheet Functions 2 March 2nd 05 04:34 PM


All times are GMT +1. The time now is 04:40 PM.

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

About Us

"It's about Microsoft Excel"