Value written in cell doesn't match value in variable

rafalrc

New Member
Joined
Mar 19, 2017
Messages
2
Greetings.
I'm developing a spreadsheet to an accounting firm with tight deadlines and I'm facing a really frustrating issue.
I'm doing calculations with currency on a vba sub. The values (in currency) are stored in multidimensional array as single. As I have to perform some divisions, the result I get has more than 2 decimal places. Then I use the round function to convert the value to 2 decimal places. I've checked the values by adding a break point and seeing the stored values in my array in locals. They HAVE two decimal places. But, when I write this variable using worksheets("gsjdk").cells(i,j).value=myarray(k,m), the value pasted in that cell has several more decimal places! This really can't happen and I can't figure out what's happening. I've even tried using worksheets("gsjdk").cells(i,j).value=round(myarray(k,m),2), but the problem persists.

Can somebody be kind enough to help me please? As I said, I have a very tight deadline and I'm starting to get desperate.

Thank you very much!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Have you tried:

worksheets("gsjdk").cells(i,j).value=Format(myarray(k,m),"0.00")

?
 
Upvote 0
Hi! Thank you for your quick response! I managed to correct the situation by multiplying all values by 100 and treating them as LONG. Then, at the moment I write them, I divide by 100 again.
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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