+ Reply to Thread
Results 1 to 15 of 15

What is wrong with this line?

  1. #1
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    What is wrong with this line?

    Hi,

    I'm getting a 'Runtime error 13 - Type mismatch' when executing this line.
    I can't figure out what's wrong with it. Could anyone help?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: What is wrong with this line?

    You have to repeat the var comparison, and I think you meant And not Or:

    Please Login or Register  to view this content.
    Rory

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: What is wrong with this line?

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 11-19-2019 at 08:54 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    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,336

    Re: What is wrong with this line?

    Guessing you can't have/refer to a whole column value.

    And you'd need to change the Or to And and repeat the "var <>"
    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


  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: What is wrong with this line?

    I assumed those were named ranges?

  6. #6
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: What is wrong with this line?

    AlphaFrog,
    I tried the parentheses and still get the error. Could it be something else?

    rorya,
    It is OR. Those two outputs are valid independently.

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: What is wrong with this line?

    An Or condition would always be true, since if it matches one it won't match the other. Did you try it?

  8. #8
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: What is wrong with this line?

    Tried And instead of Or and still get the error.
    If I remove the second condition it works, so I guess it has something to do with the syntax.

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: What is wrong with this line?

    What was the exact code you tried with the And in place?

    Also, please confirm that SN and FN are named ranges, and that none of the cells being referred to contain error values.

  10. #10
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: What is wrong with this line?

    The code I tried is the same. I only replaced OR for AND just to see if it throws an error.
    SN and FN are cell labels. They don't contain errors. The code works if I remove everything after OR.

  11. #11
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: What is wrong with this line?

    I read your first reply again and you suggested to repeat the var comparison. Why is that? Shouldn't it work using Or/And instead?

  12. #12
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: What is wrong with this line?

    Rorya, I did just that. What you suggested. I repeated the var comparison instead or putting everything on the same line and it works.
    Thanks for your help!

  13. #13
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: What is wrong with this line?

    The Or is an operator that works on the expressions either side of it, which need to evaluate to Boolean types. So:

    Please Login or Register  to view this content.
    is valid since the two expressions either side will be either True or False, but if you write this:

    Please Login or Register  to view this content.
    the evaluation steps will be:

    Please Login or Register  to view this content.
    which will be either True or False, then:

    Please Login or Register  to view this content.
    which makes no sense, hence the error.

  14. #14
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: What is wrong with this line?

    Excellent explanation. I get it now.
    Thank you rorya!

  15. #15
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: What is wrong with this line?

    Glad to help.

+ 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. Both line showing same trend instead which is wrong
    By Azam Ali in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-02-2018, 08:03 AM
  2. Data transfering to wrong line using VBA
    By Sgarner46 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-15-2016, 06:46 PM
  3. What's wrong with this line of code?
    By Ronnet2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-07-2015, 04:28 PM
  4. What is wrong with this line?
    By Solberto in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2015, 05:51 PM
  5. [SOLVED] What is wrong with this line?
    By ChartsToBe in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-27-2006, 07:10 PM
  6. what's wrong with this paste line??
    By Tre_cool in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-17-2005, 08:05 PM
  7. Something wrong in one line of VBA code
    By Daniel Bonallack in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-29-2005, 03:05 PM

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