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.
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.
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
You're not providing it with a range to round on.
Maybe this?
BSBPlease Login or Register to view this content.
You're trying to round a text literal "a".
Are you trying to round a cell in column A. In which case try
where the '2' is the number of decimal places.Please Login or Register to view this content.
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.
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
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.
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
Apparently,That said, I suspect that quote is the wrong way roundBanker'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.
As mentioned in post #4 trying to round a literal doesn't mean anything
Here's the code which uses the Excel Function method
and the code without he Excel function methodPlease Login or Register to view this content.
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks