+ Reply to Thread
Results 1 to 9 of 9

Mismatch error

  1. #1
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Mismatch error

    I keep getting a mismatch error in the following code but I don't understand why. Hoping someone can explain why. Thanks!!

    Please Login or Register  to view this content.

  2. #2
    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,464

    Re: Mismatch error

    Round would be looking for a numeric value, or a numeric variable. You have offered it a text value, "a". Perhaps you mean ... Round(Range("a" & i))
    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


  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Mismatch error

    You're not providing it with a range to round on.
    Maybe this?
    Please Login or Register  to view this content.
    BSB

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Mismatch error

    You're trying to round a text literal "a".

    Are you trying to round a cell in column A. In which case try

    Please Login or Register  to view this content.
    where the '2' is the number of decimal places.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Re: Mismatch error

    Thanks for the feedback but I tried all three of the above suggestions and still can't get it to work. I must say, I' really struggle sometimes with mismatch errors.

    Thanks again for the interest in helping me better understand this issue's cause and fix.

    Best,

    Grilleman

  6. #6
    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,464

    Re: Mismatch error

    In response to your PM, these are the instructions for uploading a file. You also need to clarify what you are trying to do.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  7. #7
    Forum Contributor
    Join Date
    04-11-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    245

    Re: Mismatch error

    I have learned this morning that when rounding numbers in Excel there is a difference between using the "Excel Round method" and using the "VBA Round method". The Excel method requires two arguments, the VBA method will accept two arguments but requires only one (that is, the second argument is optional). I also learned that the Excel Round method can be used in VBA. The attached example below shows the result when I use the diffent methods. It is column D that should display results when I use the Excel Round Method in a VBA sub. Here's where I keep getting the mismatch error.

    See attached workbook and note the following:


    Columb B: Shows result when I input the "Excel Round Formula" directly in the cells.
    Column C: Shows result when I use the VBA method (see my sub entitled "Sub VBAroundDemo()"
    Column D: I want to use the Excel method but do so inside a sub "see my sub "Sub RoundVal()"


    Thanks,

    Grilleman
    Attached Files Attached Files

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

    Re: Mismatch error

    Apparently,
    Banker's rounding always rounds 0.5 to the nearest even number and is standard in accounting, which is why Excel works that way. Arithmetic rounding rounds 0.5 up to the next number.
    That said, I suspect that quote is the wrong way round

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Mismatch error

    As mentioned in post #4 trying to round a literal doesn't mean anything

    Here's the code which uses the Excel Function method

    Please Login or Register  to view this content.
    and the code without he Excel function method

    Please Login or Register  to view this content.

+ 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. Getting error message- Run-time error '13'; type mismatch
    By UPA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2017, 03:43 AM
  2. [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
  3. Type mismatch error- What is the reason behind the error message?
    By Endre111 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2014, 02:03 PM
  4. 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
  5. 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
  6. VB error, runtime error 13 (type mismatch)
    By hindlehey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-07-2005, 08:37 PM
  7. Type Mismatch error & subscript out of range error
    By Jeff Wright in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2005, 03:06 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