Vba code not calculating decimals

ANTONIO1981

Board Regular
Joined
Apr 21, 2014
Messages
162
Hi
the final result shown in column "Amount" is ignoring any decimals that i populated in Sheet("ENGINEERS_REG_MGRS"),

hence if i sum the column will give wrong data


thanks in advance

Code:
Sub ENGINEERS_REG_MGRS_TABLE()
Dim Ray As Variant, n As Long, Ac As Long, c As Long
Ray = Sheets("ENGINEERS_REG_MGRS").Range("A1").CurrentRegion.Resize(, 17)
ReDim nray(1 To UBound(Ray, 1) * UBound(Ray, 2) + 1, 1 To 6)
c = 1
 nray(c, 1) = Ray(1, 1)
 nray(c, 2) = Ray(1, 2)
 nray(c, 3) = Ray(1, 3)
 nray(c, 4) = Ray(1, 4)
 nray(c, 5) = "Date"
 nray(c, 6) = "Amount"
For n = 2 To UBound(Ray, 1)
     For Ac = 5 To UBound(Ray, 2)
        c = c + 1
        nray(c, 1) = Ray(n, 1)
        nray(c, 2) = Ray(n, 2)
        nray(c, 3) = Format(Ray(n, 3), "mmm_yy")
        nray(c, 4) = Ray(n, 4)
        If IsDate(Ray(1, Ac)) Then
                nray(c, 5) = CDate(Ray(1, Ac))
        Else
                nray(c, 5) = Ray(1, Ac)
        End If
        nray(c, 6) = Format(Ray(n, Ac), "#,##0")
    Next Ac
Next n
Sheets("ENGINEERS_REG_MGRS_TABLE").Range("A1").Resize(c, 6) = nray
End Sub
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I think you are dropping it here:

Code:
nray(c, 6) = Format(Ray(n, Ac), "[COLOR=#ff0000]#,##0[/COLOR]")
Note that the format you chosen does not have any decimal places.
 
Upvote 0
How do you correct? like this? --> nray(c, 6) = Format(Ray(n, Ac), "#,##0.00")

i would like to take into account all decimals

thanks in advance

AC
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,348
Members
452,638
Latest member
Oluwabukunmi

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