Application.WorksheetFunction.Match with On Error: On Error Resume Next works. On Error GoTo only works once. Err.Clear has no effect.
Hi .
. Similar questions to this have been asked before, at least the parts about on error only working once and err.clear being ineffective, to reference just a few
http://www.excelforum.com/excel-char...king-once.html
http://www.mrexcel.com/forum/excel-q...orks-once.html
http://www.mrexcel.com/forum/excel-q...runs-once.html
.. alternative codes were sometimes given, but the fundamental problem did not seem to be solved
. ***In short I have many codes which use the described method below (Match / On error combination) and they appeared to work. A current code did not. So I am keen to understand exactly what is going on in case the others working was luck!!!!!
…. I try to produce a simplified example to help clearly show the issue.:
. In a sheet Main I list new Food products by their Nutrient values. For new Foods to be added I check for a Heading match, allowing for different spellings etc. of the heading by new Food products.
. So my Main sheet before running the macro uses the first 10 rows as possible Heading Spellings etc., and looks like this
Excel 2007
- A B C D E F G H I 1name Kcal Fett Eiweiß Koh 2 3Name 4Description Energie: fat Protein Kohlenhydrate 5Beschreibung kcal Fat eiweiss Kohlenhydrat 6Kilocalorien fette Eiweiß: kohlenhydrate 7Product Kilocalories Fette Carbohydrates 8Name Energy F Proteins Carbohydrates 9No. E 10K 11 12Select here!
MainSheet
. An example of a sheet with a new product to be included in the main sheet would be
Excel 2007
- A B 1name Choc Bar 2 3Energy 373 4Proteins 16 5Carbohydrates 54 6Sugers 31 7Fat 8.8 8Fibre 5.9 9Sodium 0.35
NewFood
. After running the macro I want this
Excel 2007
- A B C D E F G H I 1Kcal Fett Eiweiß Koh 2name 3Name 4Description Energie: fat Protein Kohlenhydrate 5Beschreibung kcal Fat eiweiss Kohlenhydrat 6Kilocalorien fette Eiweiß: kohlenhydrate 7Product Kilocalories Fette Carbohydrates 8Energy F Proteins Carbohydrates 9No. E 10K 11 12Choc Bar 373 8.8 16 54
MainSheet
. In the following code I attempt to control the error with the On Error GoTo. The code appears only to work for the first error occurrence. Trying Err.Clear in the appropriate place was also ineffective.
![]()
Please Login or Register to view this content.
. Can anyone help enlighten me on the fundamental problem here? Why is the above code only catching the error the first time around?? - Mainly for reasons mentioned above*** I wish to sort our this Match / On error GoTo combination problem, but code alternatives would also be welcome….A couple of alternatives I have already and include details at the end.
Thanks
Alan
...........................
2 Codes I do have working:
. 1 ) A code including An obvious extra looping for the header Values works fine ( A Similar Array alternative I have also ):
. 2) A Code Using On Error Resume Next also works fine :
Here just code . 2) for comparison ( because of Forum Thread size limitations!! )
. I enclose the example File I prepared, which includes all three codes in macro module “InputToMainFileSimpleSort”![]()
Please Login or Register to view this content.
( XL 2007 ) “ InputToMainFileSimpleSort.xlsm”
https://app.box.com/s/b58naouct28honcsxppjeareq5etfxgp
(Note for both the working codes to work the first cell in the row required for the New Food input must be selected )
………………………………………
Hi,Originally Posted by protonLeah
. Sorry about that.
. - As most people prefer not to see them it was a compromise for me to attempt to blend them out a bit. (I find I need them if I return to the thread some time later. – (It is sometimes a bit more practical for me to access my codes through the Forums later than getting at my own Back up code Files) )
. If it helps I have just edited the thread and changed the color to dark green
. Apologies again for any eye strain
Alan.
Bookmarks