Hi,
. I ran into a mysterious ( for me ) problem in a code written for an OP
( http://www.excelforum.com/excel-prog...ml#post4156568
)
. In brief .Match ( or . WorksheetFunction.Match ) was not working as I expected.
. I got the code to work by replacing the .Match bit with a simple Loop, but i am very keen to clear up the anomaly.
. I have stripped the code down to the minimum to help me explain and to aid anyone kind enough to help
. The Problem / requirement.
. – I have an ordered ( in column C ) and an un ordered ( in column F ) list of Reference Numbers , thus:
Using Excel 2007
Row\Col A B C D E F G 1Correct Order Incorrect Order 2 2405C 405C 3 3406B 408Q 4 4407D 407D 5 5408Q 406B 6 6405P 405P 7 7403A 403A 8
Mark L
......
. As part of my larger code I required to produce an Array ( rws() )full with the indicies taken from column B, but reordered in an order to reflect the disorder of the un ordered column.
. To demonstrate this pictorially I reproduce the contents of this array in column E, as follows:
. –1) Firstly I produce the results using part 3a) of the demonstration code I give at the end of this Post. This uses a simple Loop with another loop nested within in it to go through each reference number in column C and then for that reference number go through each reference number in column F, and when a Match is obtained the indicia ( given by the outer Loop Bound variable Count, rwM ) is given to the Array ( rws() ) in the position in that Array column given by the Inner loop Bound variable Count , ( rwM ) correspond to the position of the current reference number being considered from column F. – That was a mouthful... A picture paints a thousand word: Results after running part 3a) of the code
Using Excel 2007
Row\Col B C D E F 1Correct Order Incorrect Order 2 2405C 2 405C 3 3406B 5 408Q 4 4407D 4 407D 5 5408Q 3 406B 6 6405P 6 405P 7 7403A 7 403A
Mark L
.. As you see - good old fashioned looping with Array works!!!!!
..............
. – 2) Now secondly ...... as I try to break my old habits and use new Methods I attempt in part 3b) of the code to replace the inner loop with the .Match Method – As I understand its most basic form the .Match is designed to do exactly the requirement of the inner nested loop,- That is to say based on a string first argument, it searches for that string in the List given in the second argument , and having found it returns a number ( indicia) corresponding to the position in the list off that first argument string )
. Using for example, the test data above, code part 3b) gets this far (returning incorrect indices ) before crashing:
Using Excel 2007
Row\Col B C D E F 1Correct Order Incorrect Order 2 2405C 2 405C 3 3406B 2 408Q 4 4407D 4 407D 5 5408Q 7 406B 6 6405P 2 405P 7 7403A 403A.
Mark L
Can anyone please explain what is going wrong with the .Match method in part 3b).
Thanks,
Alan
Here is the test code I have been using, ( and I also upload the test File with the macro in the first sheet module )
![]()
Please Login or Register to view this content.
Bookmarks