VBA Help, Please! Rounding In A Data Array Inconsistent

milwphil

Board Regular
Joined
Aug 1, 2010
Messages
120
I'm working with a spreadsheet that is not rounding consistently. If I cut and paste 1.5 it rounds to 2 (which is correct, .5 should round to 1). However, if I cut and paste .5, it rounds to 0.

Any insight....WOULD BE GREATLY APPRECIATED...I'm fresh out of ideas!
Code:
If Val(dataArray(tmpRow, tmpCol)) <> Val(WorksheetFunction.Round(Val(dataArray(tmpRow, tmpCol)), 0)) Then
                    cellWarning = True
                    Call updateWarnText(tmpRow, tmpCol, "Number of Levels, was changed from " & dataArray(tmpRow, tmpCol) & " to " & [B][COLOR=red]Round(Val(dataArray(tmpRow, tmpCol)), 0))[/COLOR][/B]
                    dataSheet.Cells(tmpRow, tmpCol).Value = Val(WorksheetFunction.Round(Val(dataArray(tmpRow, tmpCol)), 0))
                    dataSheet.Cells(tmpRow, tmpCol).NumberFormat = "General"
                End If
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
2 initial thoughts:

- I notice you are using "worksheetfunction.round" elsewhere, but only "round" on the bit that you've highlighted

- are you using 0.5 or ".5"?
 
Upvote 0
You are using WorkSheetFunction.Round in one place and the VBA function Round in the other.
 
Upvote 0
Thanks for the quick responses!

So would changing Round to Worksheet.Round potentially resolve the issue or am I about to enter a world of re-engineering this entire code?

I'm hoping replacing Worksheet.Round would resolve the issue.

I'll try it right now....and post my results.

THANKS AGAIN!
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top