Excel VBA variable rounding/decimal place issue

rebeccawilson100

New Member
Joined
Jun 23, 2016
Messages
7
Hello,

First time poster so bare with me.

I have written a VBA code and am having some issues with a decimal place. Unfortunately i cannot post the code as it is work related.

Essentially I have a value assigned to a Variable A using A=Application.Worksheetfunction.round(B,2). when i hover over the variable it only shows 2dp (which is what i want) but unfortunately when this value is deposited into a Cell later in the code it shows the value to more dp (around 10 or so).

I have used Cells(X,Y)=A to input into the spreadsheet. I checked that the variable isn't reassigned just before assigning to a cell and it still shows 2dp.

After googling i found the format(B,"#.00") but this gave the same end result.

I think the issue may occur when placing the value into a cell as the variable has the correct assigned amount of dp.

Any ideas?

Thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello,

Managed to fix the issue by adding the rounding in right at the end ie: Cells(X,Y)=applicaiton.worksheetfunciton.round(A,2)

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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