-2

I have a huge Excel VBA file (xlsm). It used to be able to run it without any problem. Now my co-worker runs it without any problem. But when I run it, it keeps giving me this "Run Time Error '13'". I just installed a patch called: "excel2010-kb2956142-fullfile-x64-glb" on my Windows 7, 64bit machine.

Here is the code snipet:

iPos2 = 0
On Error Resume Next
iPos2 = Application.Match(sComponent, sBsLvlShort(), 0)
On Error GoTo 0

The debug stops at the line with: Application.Match What else can be done? I know the Excel has no problem.

Thanks for any help.

Jennifer

3
  • 1
    At a minimum, post the code from the line that is generating the error. A few lines above and below wouldn't hurt. Please see How to create a Minimal, Complete, and Verifiable example.
    – user4039065
    Jul 23, 2015 at 20:11
  • What is sBsLvlShort? An array? Would a dictionary be a better choice?
    – user4039065
    Jul 23, 2015 at 20:18
  • It is an array with 5 items. I cannot change the code since it is legacy code not mine. It has been runing without any problem until I ran it now.
    – JenZ
    Jul 23, 2015 at 20:28

1 Answer 1

1

Enter the Debug mode when the code "breaks".

Then, in the VBE "Immediate" pane, enter the following statement and press the Return key:

?TypeName(iPos2)

And tell me what it prints on the next line. Then again in the Immediate pane, enter this statement and press the Return key:

?Application.Match(sComponent, sBsLvlShort(), 0)

Then, tell me what is printed on the next line.

Whatever is being stored in the array is causing a mismatch with the data type associated with the iPos2 variable.

One other possibility is that you have inadvertently enabled the option in VBE to "Break on All Errors". In the VBE check Tools | Options | General and ensure the "Break on Unhandled Errors" option is checked. Otherwise, even errors wrapped in the On Error Resume Next statement will raise (the Application.Match function will return an error type if the value isn't found in the array).

Otherwise what is actually in this array? Have you verified this using the Locals pane to examine its contents? (If you don't know how to do this, Google will be useful!)

If it is not containing what you expect it to contain, then you need to work backwards and find the line of code that assigns to this variable, and debug from there. At that point, it seems likely it could be user error (i.e., you've provided the wrong inputs for the procedure, in which case an error is often to be expected).

6
  • Thank you very much, David! I will test it tomorrow morning.
    – JenZ
    Jul 23, 2015 at 20:42
  • For now I have to leave for home. And I also got another error at: another line that runs Application.Match that also involves sBsLvlShort: iNdxGroup = Application.Match(sExpGroup, sBsLvlShort(), 0) On Error GoTo 0
    – JenZ
    Jul 23, 2015 at 20:43
  • Here is what I got: ?TypeName(ipos2) Integer ?Application.Match(sComponent, sBsLvlShort(), 0) Error 2042
    – JenZ
    Jul 24, 2015 at 12:34
  • 1
    Yes, the setting is "Break on All Errors". I just switched it to "Break on unhandled errors"
    – JenZ
    Jul 24, 2015 at 12:35
  • After the setting change, it works! Thank you so much!
    – JenZ
    Jul 24, 2015 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.