+ Reply to Thread
Results 1 to 25 of 25

Type mismatch error

  1. #1
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Exclamation Type mismatch error

    I keep getting the error "Run-Time error '13': Type mismatch" and I can't figure out why.
    This is my code below, please help

    Please Login or Register  to view this content.
    Last edited by Rachel5694; 07-13-2018 at 08:56 AM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831
    Just typos …
    But according to forum rules :

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

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  3. #3
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: Type mismatch error

    I am sorry, I am new to this forum and did not know about that rule. It should be correct now. Thank you for making me aware of the rule,

  4. #4
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: Type mismatch error

    Since the error is fixed, can someone please help me I'm still stuck on it There may be an easy fix but I am fairly new to VBA so I am unable to find it.

  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,911

    Re: Type mismatch error

    It looks like your code is the wrong way round and you wanted:

    Please Login or Register  to view this content.
    Last edited by rorya; 07-13-2018 at 10:50 AM. Reason: Missed a 'Cell' error

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,228

    Re: Type mismatch error

    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Type mismatch error


    As Cell does not exists (typo) just use instead Range (or Cells in case of numeric row / column as you can read in VBA inner help) …

  8. #8
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: Type mismatch error

    hm it didn't work, I am not getting any errors but nothing is happening.

    I have data in sheet one that the code is supposed to pull from, then in the second sheet called "reports" I have command button that I am pressing to start the code and then populate the value "good" into the sheet "report"

  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,911

    Re: Type mismatch error

    What cells are you supposed to be checking? The code is checking if R2 is >= Q2.

  10. #10
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: Type mismatch error

    "Range" and "Sheets" doesn't appear to be working either.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: Type mismatch error

    yes that is correct. if the value of R2 is greater than or equal to the value in q2

  12. #12
    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,911

    Re: Type mismatch error

    Put a breakpoint in the code then step through it with f8 to see where it doesn't do what you expect.

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Type mismatch error

    Quote Originally Posted by Rachel5694 View Post
    if the value of R2 is greater than or equal to the value in q2
    R2 & Q2 of which worksheet(s) ?!

  14. #14
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: Type mismatch error

    Oh sorry, R2 and Q2 would be in worksheet "Sheet1"

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    As a beginner starter :

    PHP Code: 
    Private Sub CommandButton3_Click()
        If 
    Range("Sheetl!R2").Value >= Range("Sheetl!Q2").Value Then Range("Report!A2").Value "Good"
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  16. #16
    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,911

    Re: Type mismatch error

    Since the button is on the Reports sheet, that won't work. You need to use:

    Please Login or Register  to view this content.
    not:

    Please Login or Register  to view this content.

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Type mismatch error


    As both work, my Range syntax is just an Excel basics as you can see just with a formula instead any code …

    But you may be right if the code is located in a worksheet module ! (Error #400 in this case …)
    Last edited by Marc L; 07-13-2018 at 11:26 AM.

  18. #18
    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,911

    Re: Type mismatch error

    Quote Originally Posted by Marc L View Post
    As both work
    Only, as I said, they don't. It's code behind a commandbutton_click so it has to be in a worksheet code module.

  19. #19
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Another way !


    Only if the code is located within the worksheet Report module, as a beginner starter :

    PHP Code: 
    Private Sub CommandButton3_Click()
        If 
    Sheet1.[R2-Q2] >= 0 Then [A2].Value "Good"
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 07-13-2018 at 11:35 AM.

  20. #20
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb A variation …


    As this kind of code is very superfluous for this kind of stuff just using a child level formula,
    if really a code is needed just use the same formula, as a very beginner starter :

    PHP Code: 
    Private Sub CommandButton3_Click()
        [
    A2].Value = [IF(Sheet1!R2>=Sheet1!Q2,"Good","")]
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 07-13-2018 at 11:45 AM.

  21. #21
    Registered User
    Join Date
    06-28-2018
    Location
    US
    MS-Off Ver
    2016
    Posts
    89

    Re: Try this !

    For some reason I am getting an "Expected: Expression" error with ">=" ?

  22. #22
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,228

    Re: Type mismatch error

    Back & Forth all night long....Just request OP to upload a sample and put them out of their misery!!!

  23. #23
    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,911

    Re: Type mismatch error

    What, and spoil all the fun?

  24. #24
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Try this !

    Quote Originally Posted by Rachel5694 View Post
    For some reason I am getting an "Expected: Expression" error with ">=" ?
    As all rock on my side ! I let rorya playing without any attachment …

  25. #25
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,228

    Re: Type mismatch error

    The things we do for fun lol...

+ 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. [SOLVED] RunTime Error 13 ( type mismatch ) error is comming TextboxAfter_Update
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-04-2017, 03:55 AM
  2. [SOLVED] Type Error Mismatch
    By Jiptastic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2012, 07:21 PM
  3. Run Type error 13 Type Mismatch
    By Affan Khan in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-13-2012, 12:58 PM
  4. [SOLVED] Run-type error 13 type mismatch
    By misop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-05-2012, 04:08 AM
  5. Complile Error: Type Mismatch ??? After adding error trap
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2012, 03:50 PM
  6. Conditional Formatting - Run Time Error '13' Type Mismatch Error
    By ksp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-17-2011, 07:37 PM
  7. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

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