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

On one sheet, column 5 is the customer number and column 6 is the new
customer number. I do a little formatting to ensure both columns are text
and the old customer numbers are 7 characters in length. If they are not 7
characters long, I add a space at the end of the old customer number. Next I
sort these 2 columns based on the old customer number. Finally, I load these
items into a 2 dimensional array. So far, so good, as all of the old
customers numbers are sorted in descending order.

Next, I move to the data sheet and and do the same same formatting and
sorting to the old customer number. Again, so far, so good as all of the old
customers numbers are sorted in descending order.

Next I run a little loop to compare the first item on the data sheet to the
first item in the array.....else

If the customer number is less than the first item in the array, I move to
the next customer number.....else

If the customer number equals the first item in the array, I add the new
customer number to the data sheet for that row and move to the next row.

If the customer number is greater than the first item in the array, I
increase the array index by 1 adn re-check the old customer number. (I'm
comparing the same record with the next item in the array.)

What's driving me crazy is the data is sorted like I expect but when it
compares the customer number to the item in the array, the lower item is
greater than the array item, so it is increasing the array index, instead of
moving to the next customer number.

For example, when I compare customer number "@AMXRWD" to the array item
"10D5671", I expect it to move to the next customer number since "10D5671"
follows "@AMXRWD" when the data is sorted.

Instead, it appears that "@AMXRWD" is greater and is increasing the array
index; which throws off the rest of the items.

Any suggestions or help on this string comparison would be greatly
appreciasted. I have include the code for the loop below.

Thanks for the help.

' cells reference is the customer number
' code (1,y) is the old customer number in the array
' code (2,y) is the new customer number in the array

r = 1
y = 1

Do Until Len(Trim(Cells(r, 1))) = 0

If Cells(r, 2) < Code20(1, y) Then
r = r + 1
Else
If Cells(r, 2) = Code20(1, y) Then
Cells(r, 3).NumberFormat = "@"
Cells(r, 3) = Code20(2, y)
r = r + 1
Else
If Cells(r, 2) Code20(1, y) Then
y = y + 1
End If
End If
End If

Loop


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default String Comparison

Hi Shaves,

You can control the string comparison
mode.

At the head of your module, before any
procedures, try inserting the statement:

Option Compare Text


For further information, see the 'Option Compare
Statement' in VBA help.



---
Regards.
Norman


"Shaves" wrote in message
...
On one sheet, column 5 is the customer number and column 6 is the new
customer number. I do a little formatting to ensure both columns are text
and the old customer numbers are 7 characters in length. If they are not
7
characters long, I add a space at the end of the old customer number.
Next I
sort these 2 columns based on the old customer number. Finally, I load
these
items into a 2 dimensional array. So far, so good, as all of the old
customers numbers are sorted in descending order.

Next, I move to the data sheet and and do the same same formatting and
sorting to the old customer number. Again, so far, so good as all of the
old
customers numbers are sorted in descending order.

Next I run a little loop to compare the first item on the data sheet to
the
first item in the array.....else

If the customer number is less than the first item in the array, I move to
the next customer number.....else

If the customer number equals the first item in the array, I add the new
customer number to the data sheet for that row and move to the next row.

If the customer number is greater than the first item in the array, I
increase the array index by 1 adn re-check the old customer number. (I'm
comparing the same record with the next item in the array.)

What's driving me crazy is the data is sorted like I expect but when it
compares the customer number to the item in the array, the lower item is
greater than the array item, so it is increasing the array index, instead
of
moving to the next customer number.

For example, when I compare customer number "@AMXRWD" to the array item
"10D5671", I expect it to move to the next customer number since "10D5671"
follows "@AMXRWD" when the data is sorted.

Instead, it appears that "@AMXRWD" is greater and is increasing the array
index; which throws off the rest of the items.

Any suggestions or help on this string comparison would be greatly
appreciasted. I have include the code for the loop below.

Thanks for the help.

' cells reference is the customer number
' code (1,y) is the old customer number in the array
' code (2,y) is the new customer number in the array

r = 1
y = 1

Do Until Len(Trim(Cells(r, 1))) = 0

If Cells(r, 2) < Code20(1, y) Then
r = r + 1
Else
If Cells(r, 2) = Code20(1, y) Then
Cells(r, 3).NumberFormat = "@"
Cells(r, 3) = Code20(2, y)
r = r + 1
Else
If Cells(r, 2) Code20(1, y) Then
y = y + 1
End If
End If
End If

Loop



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
Comparison of alphanumeric string ErExcel Excel Discussion (Misc queries) 4 May 7th 07 02:14 PM
String Comparison using Like Problem sbowman Excel Programming 3 August 23rd 06 03:17 PM
comparison string VBA excell stats Excel Discussion (Misc queries) 5 March 16th 06 10:12 PM
String Comparison Purnima Excel Programming 9 March 8th 05 11:13 AM
VB String Comparison In Excel Craig[_8_] Excel Programming 2 November 24th 03 07:47 PM


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