Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel sort vs VBA

This is part of a sequence that was sorted in ascending order in Excel...

Ad Spend - Arbeitsagentur - Press ()
Ad Spend - Arbeitsagentur - Trade Magazines/Press ($)
Ad Spend - Arbeitsagentur - Trade Magazines/Press ()
Ad Spend - Arbeitsagentur (Group Label)
Ad Spend - Cadremploi - Online ($)
Ad Spend - Cadremploi - Online (£)

When running a loop in VBA, the value in the 4th line is less than the value
in the 3rd. Why did is this so?

Is there a way of comparing cells so that the hireachy is the same as Excel
uses for sorting.

Currently I am using..

if range(CellAdress).value < range(CellAdress.offset(1,0)).value then...
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel sort vs VBA

The problem is not what the line should say, it is how Excel has sorted the
line compared to how visual basic regards the data. Excel says one is greater
than the other, while VBA says that one is less than the other.

To distill the problem to the bare minimum..

In Excel the formula =IF("-""(","Yes","No") gives the result "No"

In VBA the routine...

Sub Test()
If "-" "(" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

....gives the result "Yes"



"Norman Jones" wrote:

Hi Glynn,

Perhaps:

Ad Spend - Arbeitsagentur (Group Label)


should be

Ad Spend - Arbeitsagentur - (Group Label)

( missing hyphen ?)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Excel sort vs VBA

VBA looks right to me. Asc("-") is 45, Asc ("(") is 40, so it should be. Why
sort does it the other way, is beyond me at this minute.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Glynn Consulting Ltd" wrote
in message ...
The problem is not what the line should say, it is how Excel has sorted

the
line compared to how visual basic regards the data. Excel says one is

greater
than the other, while VBA says that one is less than the other.

To distill the problem to the bare minimum..

In Excel the formula =IF("-""(","Yes","No") gives the result "No"

In VBA the routine...

Sub Test()
If "-" "(" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

...gives the result "Yes"



"Norman Jones" wrote:

Hi Glynn,

Perhaps:

Ad Spend - Arbeitsagentur (Group Label)


should be

Ad Spend - Arbeitsagentur - (Group Label)

( missing hyphen ?)




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Excel sort vs VBA

There are many differences between comparisons in Excel & VBA, particularly
with different data types. However in this particular case to get VBA to
simulate Excel head your module
Option Compare Text

and you should find the result of your test demo is reversed to same as
Excel

But need to do a lot more to fully simulate Excel

Regards,
Peter T


"Glynn Consulting Ltd" wrote
in message ...
The problem is not what the line should say, it is how Excel has sorted

the
line compared to how visual basic regards the data. Excel says one is

greater
than the other, while VBA says that one is less than the other.

To distill the problem to the bare minimum..

In Excel the formula =IF("-""(","Yes","No") gives the result "No"

In VBA the routine...

Sub Test()
If "-" "(" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

...gives the result "Yes"



"Norman Jones" wrote:

Hi Glynn,

Perhaps:

Ad Spend - Arbeitsagentur (Group Label)


should be

Ad Spend - Arbeitsagentur - (Group Label)

( missing hyphen ?)




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
Updating workbook with an alpha sort sheet and a numeric sort shee cjlatta Excel Discussion (Misc queries) 2 January 28th 09 12:00 AM
Sort from SQL view does not sort in EXCEL Pat M - City of Reno Excel Discussion (Misc queries) 0 August 31st 07 07:38 PM
Pls. reply Sort Data and copy to next coulmn when sort order chang shital shah Excel Programming 1 August 19th 05 02:51 PM
Excel sort by Fill Color by custom list sort Dash4Cash Excel Discussion (Misc queries) 2 July 29th 05 10:45 PM
Excel Sort function should not sort the cell formatting! Lisa D.N.1 Excel Worksheet Functions 1 December 28th 04 08:37 PM


All times are GMT +1. The time now is 04:20 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"