+ Reply to Thread
Results 1 to 10 of 10

Error finding string in a range of cells

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

    Error finding string in a range of cells

    Hi,

    I have the following code in my program. And it runs file....ie...no run-time errors generated.

    When i change the 1 to a variable "lcntr1".......i get a runtime-error of type mismatch 13.

    runs ok:
    Please Login or Register  to view this content.
    does not run ok:
    Please Login or Register  to view this content.


    lcntr1 is defined as a long variable type and has the value of 2............i dont get why this fails.......


    any ideas? stumped on this one........or i have just been looking at this way to long
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Error finding string in a range of cells

    Please Login or Register  to view this content.
    Elegant Simplicity............. Not Always

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

    Re: Error finding string in a range of cells

    andy that does not work

    I cut-n-pasted what you sent into the vba section and it highlights in red........letting me know the syntax is wrong.

    thanks for trying though.........any other ideas?

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

    Re: Error finding string in a range of cells

    i still dont know the answer but found this as well

    if take what does seem to work (see below):
    Please Login or Register  to view this content.

    and replace the 1 with a 2........then it does not work........

    Please Login or Register  to view this content.

  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: Error finding string in a range of cells

    lcntr1 is indeed the looping variable, however, in your code above you typed lctrl (the last character is a lowercase L instead of 1), which is an undeclared variable that has had no value assigned to it. Change the lowercase L to a 1 so that it is lcntr1 and it should work.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

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

    Re: Error finding string in a range of cells

    tigeravatar, i tried what you suggested and it still did not work. can you attach an udpated file so i can look at what you did.......

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

    Re: Error finding string in a range of cells

    i think i figured it out...........it has to do with the "After:" section.

    Recall, that it works with a 1........but not ANY number larger than this.........if you look at my "After:" section you see i specify cells (1,3)...........i changed this from 1,3 to 2,3 and i was able to get program to run for a value of 2 that had previously failed...........

    i will write more once i confirm futher

  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: Error finding string in a range of cells

    You can omit the After:= argument, there's no need to include it

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Error finding string in a range of cells

    you're right-the after cell (if you specify one) must be within the search range or you will get that error
    Josie

    if at first you don't succeed try doing it the way your wife told you to

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

    Re: Error finding string in a range of cells

    thanks guys...........

+ 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