+ Reply to Thread
Results 1 to 15 of 15

Type 13 Runtime Error Using String Variable in Evaluate Function

  1. #1
    Registered User
    Join Date
    03-10-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    6

    Type 13 Runtime Error Using String Variable in Evaluate Function

    I'm a first time contributor to this forum so thanks for letting me join the ranks.

    I've got a sub that's evaluating each cell in the range "StoreNames" to see if it is in an adjacent list. If it is not in the list the cell value is added to the MissingStores variable and the counter is increased by one.

    Everything works fine except for the "Store" variable in the OR function is giving me a "type mismatch" error. I can see the variable is set correctly (the first store is listed as "American Fork") yet the runtime error breaks the code.

    Any advice?


    Please Login or Register  to view this content.
    Last edited by alansidman; 03-10-2014 at 05:13 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between
    Please Login or Register  to view this content.
    tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    03-10-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Thanks for the feedback. I'll be sure to add this specification going forward.

  4. #4
    Forum Contributor
    Join Date
    01-25-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    434

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Rather than fixing this problem, I'm suggesting an alternative solution to what you're trying to achieve

    Although your user will be aware of the information they need, as it will appear in a message box, once OK has been clicked all that info has gone

    How about once new data has been imported, they can just look at the StoreNames sheet

    add a new column to test if data for all stores has been imported

    Please Login or Register  to view this content.
    this can be copied down do row 50 in column J, as this is your fixed list of stores
    Last edited by ThirtyTwo; 03-10-2014 at 05:34 PM.

  5. #5
    Registered User
    Join Date
    03-10-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Thanks for the reply ThirtyTwo. I actually used conditional formatting to do the same thing with the cells in range StoreNames so the data is available on the worksheet already. I'm simply trying to synthesize this data a little more for the user. My real issue is using a string variable in VBA function. For whatever reason the posted code creates a type mismatch error.

  6. #6
    Forum Contributor
    Join Date
    01-25-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    434

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    I created a book to evaluate the code, but no matter what I try, I can't get the type mismatch error

  7. #7
    Registered User
    Join Date
    03-10-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Add text to the StoreNames range and this will produce the error. The Store range will hold the text value in quotes.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    @VBADoesMyWork: what would make it easier for everyone would be if YOU uploaded a workbook with worksheets, data, formulas, Named Ranges and code ... complete with instructions as to how you can consistently produce the error. Then it might be possible to simulate the problem in a "life-like" scenario.

    That beats second guessing, and trying to create a test environment for you.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Perhaps you require:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Try change to

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-10-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Thanks Izandol! That worked perfectly. However, I don't understand why adding the triple set of quotations solved the problem. Will you help me understand?

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Better use Address property for both String/Numeric type comparison.
    Please Login or Register  to view this content.

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Quote Originally Posted by VBADoesMyWork View Post
    However, I don't understand why adding the triple set of quotations solved the problem.
    Formula will be =OR("Store"=$J$2:$J$50) with quotes included.
    In VBA you must double quotes within formula string to escape quote - else VBA will see it as end of string.

    Jindon is correct it will be better to use .Address if range may include number data also - if range is on separate sheet, you must include sheet name in address string.

  14. #14
    Registered User
    Join Date
    03-10-2014
    Location
    Salt Lake City, UT
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    I see. I had tried with double quotes but I didn't consider triple quotes. The .Address property would return the cell address rather than the value (which is not what I'm looking for).

    Thanks again for the help!

  15. #15
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Type 13 Runtime Error Using String Variable in Evaluate Function

    Quote Originally Posted by VBADoesMyWork View Post
    The .Address property would return the cell address rather than the value (which is not what I'm looking for).
    It will produce same result.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Runtime Error 91 - object variable or with block variable not set
    By 0celj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2013, 09:40 PM
  2. Error using Clng function in vba to convert string to long data type
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-05-2011, 06:12 AM
  3. runtime error 91 object variable or With block variable not set
    By tullemann in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2011, 01:27 PM
  4. Runtime error 91 Objecr Variable of With block variable not set
    By s_ali_hassan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2010, 05:28 AM
  5. Evaluate a Variable Name from a String
    By Developer of the Caribbean in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-11-2005, 03:55 AM

Tags for this Thread

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