+ Reply to Thread
Results 1 to 11 of 11

Type MisMatch error (13) with if statement using loop

  1. #1
    Registered User
    Join Date
    04-23-2010
    Location
    Albuquerque, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Talking Type MisMatch error (13) with if statement using loop

    I am having a problem with this code,

    Please Login or Register  to view this content.
    The macro will not run this IF loop which calls a macro to highlight a cell if the values match. I get a type mismatch error when it comes to the veritable. If the range is changed to a set value the macro works but I can't figure out why this error is occurring. Could someone help me with this?
    Last edited by mdnghtsnpr; 04-26-2010 at 10:37 AM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Type MisMatch error (13) with if statement using loop

    It may be because you are defining the variables as integers. Integer's max value is 32767 (according to VBA's help), but in Excel, the column can be considerably longer. Try setting the variables to Long instead, does that work?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Type MisMatch error (13) with if statement using loop

    Scratch my last advice, that was NOT correct.

  4. #4
    Registered User
    Join Date
    04-23-2010
    Location
    Albuquerque, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Type MisMatch error (13) with if statement using loop

    Tried that but still no dice but thanks for the idea

  5. #5
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Type MisMatch error (13) with if statement using loop

    Look at the line that is failing:

    Please Login or Register  to view this content.
    What is Range("A" + a)?

    Did you mean Cells(a, "A")?

  6. #6
    Registered User
    Join Date
    04-23-2010
    Location
    Albuquerque, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Type MisMatch error (13) with if statement using loop

    nope because the code is taking "A" which is a column and adding the loop to that number so as the code runs its supose to go cell by cell down the sheet comparing to a seperate sheet. So ("A" + a) is suppose to start at cell "A2".

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Type MisMatch error (13) with if statement using loop

    That may be what you intended, but that is not the correct syntax. Try running it with how I changed it for range(A+a) and range (A+b).

  8. #8
    Registered User
    Join Date
    04-23-2010
    Location
    Albuquerque, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Type MisMatch error (13) with if statement using loop

    tried that and once the quotation marks are removed it changes it to a variable character.

  9. #9
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Type MisMatch error (13) with if statement using loop

    I didn't remove any quotation marks, I changed the order. The sytnax is:
    Cells(Row,Column)

    Use this:

    Please Login or Register  to view this content.
    I tested it in your sample workbooks and it seemed to work.

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: Type MisMatch error (13) with if statement using loop

    Change the Integer declarations to Long.

    Range("A"+a) should be Range("A" & a) since the range parameter is a string you use the concatenate operation "&" to convert the "a" quantity to a string and append to "A" to get "A2", etc
    Ben Van Johnson

  11. #11
    Registered User
    Join Date
    04-23-2010
    Location
    Albuquerque, USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Type MisMatch error (13) with if statement using loop

    Thanks Proton that worked.

+ 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