More decimals??

excelis

New Member
Joined
Jun 3, 2010
Messages
38
Dear all,

I have come across this macro but the result that is giving is a number without decimals, even if the values of the cells have more decimals like 13,26 for example.

Do you know how and where should i write that i want the result with more decimals, for example instead of 100 to be 100,2435 ??

Thank you for your help!!


Code:
Sub SumColorCount()
 Dim Blue5 As Integer, _
 Red3 As Integer, _
 Yellow6 As Integer
 Dim Data As Range
 Dim Cell As Range

 Set Data = Range("A1:A1000")
 For Each Cell In Range("Data")
 If Cell.Interior.ColorIndex = 5 Then
 Blue5 = Blue5 + Cell.Value
 ElseIf Cell.Interior.ColorIndex = 3 Then
 Red3 = Red3 + Cell.Value
 ElseIf Cell.Interior.ColorIndex = 6 Then
 Yellow6 = Yellow6 + Cell.Value
 End If
 Next

 Range("F10").Value = "Blue = " & Blue5
 Range("F11").Value = "Red = " & Red3
 Range("F12").Value = "Yellow = " & Yellow6

 MsgBox "     You have: " & vbCr _
 & vbCr & "   Blue  " & Blue5 _
 & vbCr & "      Red     " & Red3 _
 & vbCr & "    Yellow   " & Yellow6, _
 vbOKOnly, "CountColor"

 Range("F10:F12").Value = ""

</pre>
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
When you are using Integer this basically means whole numbers if you change this to Double this will give you decimal points.

So look to change the following (I haven't tested this).

Code:
Dim Blue5 As Integer, _
 Red3 As Integer, _

To
Code:
Dim Blue5 As [COLOR=royalblue]Double[/COLOR], _
 Red3 As [COLOR=royalblue]Double[/COLOR], _
 
Upvote 0
Pleaed to read you have a solution.;)
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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