+ Reply to Thread
Results 1 to 8 of 8

Instr runtime error

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Instr runtime error

    I have this string which contains a hyphen "-". If i run the following code such that my temp_string has a "-" in it ........code will run fine. However, if i remove the "-" from the temp_string then the code has a run time error of "Invalid procedure call or argument".

    I know that the reason i get this run time error is that i am looking for a hyphen in a string that has no hyphen ...........not sure what to do. Need some way of making program not "stop" ......not sure.


    Please Login or Register  to view this content.
    Last edited by welchs101; 06-08-2011 at 02:35 PM.

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Instr runtime error

    ook, i must be getting tired. I just realized that i shoudl just check to see if the "-" is in the string before i try and create a new string.

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Instr runtime error

    welchs101,

    What the code is trying to do is get all text to the left of the hyphen, then remove leading/ending spaces. If there is no dash, there's no text, so when it tries to get text to the left of the dash you get an error. Try this instead:
    Please Login or Register  to view this content.

    Hope that helps,
    ~tigeravatar

    EDIT: Looks like you got it before I replied

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Instr runtime error

    Hi thanks for the info. I was kinda headed that way.

    I did have another question. See enclosed file.

    I am trying to parse all the values in col-A of sheet1. For some reason when you run this code (again see enclosed macro) when it reaches a string with a "-" in it ......code just seems to end like it finished.


    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Instr runtime error

    welchs101,

    Give this a try instead:
    Please Login or Register  to view this content.


    Hope that helps,
    ~tigeravatar

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Instr runtime error

    I closed excel and then restarted it.............re-ran the macro AND IT RAN!!!!!!!!!!!!!

    Any ideas why closing down excel and restarting would make it run?

  7. #7
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Instr runtime error

    tigeravatar, thanks for the code.......i like it much better than mine. thanks.

    any idea why restarting excel caused program to "work"....very strange.

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Instr runtime error

    I'm not sure. You declare done = false in the code before the loop, so it should have run without needing to close excel and reopen it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1