# Decimal values ignored by script

#### Alex Piotto

##### Board Regular
' Morning everyone...

I am making a sum of numbers (negatives in that case) from a column.
The numbers are formatted. Like 1,250.55...
I show the result in a textbox. The result is formatted too. Like 1,250.55...

VBA Code:
``````'SUM NEGATIVES AND PUT RESULT IN TEXTBOX4
Dim x As Long
Dim c As Range
Dim tot As Integer
x = Cells(Rows.Count, "B").End(xlUp).Row
tot = 0
For Each c In Range("H14:H" & x)
If c.Value < 0 Then
tot = tot + c.Value
End If
Next c
ActiveSheet.TextBox4.Value = tot
ActiveSheet.TextBox4.Value = Format(TextBox4.Value, "#,##0.00")``````

But the decimals are always zero zero. There is a rounding up playing here without asking....

How to avoid it?

### Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

##### Well-known Member
Hi
VBA Code:
``Dim tot As Integer``
tot is integer
so you have to
VBA Code:
``Dim tot As Double``

#### Alex Piotto

##### Board Regular
Fast as a flash! Thanks a lot.

##### Well-known Member
You are welcome
and thank you for the feedback
Be happy

#### Alex Piotto

##### Board Regular

If there are no values I get an error... If I do what i put in green it is going to work?

VBA Code:
``````'SUM NEGATIVES AND PUT RESULT IN TEXTBOX4
Dim x As Long
Dim c As Range
Dim tot As Double
x = Cells(Rows.Count, "B").End(xlUp).Row
tot = 0

' if c = "" then exit sub else

For Each c In Range("H14:H" & x)
If c.Value < 0 Then
tot = tot + c.Value
End If
Next c

' end if``````

##### Well-known Member
Well
Try
VBA Code:
``````Dim x As Long
Dim c As Range
Dim tot As Double
x = Cells(Rows.Count, "B").End(xlUp).Row
tot = 0
For Each c In Range("H14:H" & x)
If c <> "" And c.Value < 0 Then
tot = tot + c.Value
End If
Else
tot = 0
End If
Next c``````

#### Alex Piotto

##### Board Regular

One End If too much...

##### Well-known Member
Sorry
VBA Code:
``````Dim x As Long
Dim c As Range
Dim tot As Double
x = Cells(Rows.Count, "B").End(xlUp).Row
tot = 0
For Each c In Range("H14:H" & x)
If c <> "" And c.Value < 0 Then
tot = tot + c.Value
End If
Else
tot = 0
End If
Next c``````

#### Alex Piotto

##### Board Regular
It is the same script ...

##### Well-known Member
VBA Code:
``````Dim x As Long
Dim c As Range
Dim tot As Double
x = Cells(Rows.Count, "B").End(xlUp).Row
tot = 0
For Each c In Range("H14:H" & x)
If c <> "" And c.Value < 0 Then
tot = tot + c.Value

Else
tot = 0
End If
Next c``````

Replies
2
Views
64
Replies
5
Views
255
Replies
6
Views
68
Replies
3
Views
187
Replies
7
Views
316

1,127,861
Messages
5,627,314
Members
416,239
Latest member
Counselor85027

### 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.

### Which adblocker are you using?

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

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