Problem with assigning whole numbers to array but preserving 2 decimal places

WednesdayC

Board Regular
Joined
Nov 7, 2010
Messages
201
Office Version
  1. 2016
Platform
  1. MacOS
Hi All

Please can someone help me. I am assigning a range to an array. The numbers (column 7) are all formatted to 2 decimal places, but when the numbers were written to the array, the numbers were coming through at 1, 2 or more decimal places, with whole numbers, not displaying any decimal places. I have managed to capture decimal numbers to 2 decimal places in the array, by capturing the result to a variable (probably not the best way to do this), formatting the variable and then adding to the array, but the whole numbers are staying as whole numbers, no matter what I try!

Any help, as always would be much appreciated, as I am really stuck.

Regards

Wednesday
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
VBA Code:
Sub ArrayWithDecimals()
     With Range("E14:L30")                                      'your range to 2 arrays
          aValues = Evaluate("=--text(" & .Address & ",""0.00"")")     'are again numbers but with only 2 decimals
          aTexts = Evaluate("=text(" & .Address & ",""0.00"")")     'are strings
     End With
End Sub
 
Upvote 0
Solution
VBA Code:
Sub ArrayWithDecimals()
     With Range("E14:L30")                                      'your range to 2 arrays
          aValues = Evaluate("=--text(" & .Address & ",""0.00"")")     'are again numbers but with only 2 decimals
          aTexts = Evaluate("=text(" & .Address & ",""0.00"")")     'are strings
     End With
End Sub
Hi BSALV
Thank you for replying to me, although I don't completely understand it. I have never used Evaluate before. I am presuming that aValues and aTexts are regular arrays and I can loop through these? Do I need to use both?
I will try to work it out.
Regards
Wednesday
 
Upvote 0
Hi BSALV
Thank you for replying to me, although I don't completely understand it. I have never used Evaluate before. I am presuming that aValues and aTexts are regular arrays and I can loop through these? Do I need to use both?
I will try to work it out.
Regards
Wednesday
Hi BSALV
Recap - thank you so much!
The text version is working and keeping the trailing zeros.
You have been a huge help!

Regards
Wednesday
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,182
Members
448,948
Latest member
spamiki

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