3

I'm trying to make a VBA module to sum cells excluding cells with a strikethrough. The code I'm using below works great, but will not calculate decimals. For instance, '5 + 5.50' will equal 10.00 I want to the code to keep decimals values up to two decimal places so that the sum above would be 10.50.

Public Function ExcStrike(pWorkRng As Range) As Long
'Update 20140819
Application.Volatile
Dim pRng As Range
Dim xOut As Long
xOut = 0
For Each pRng In pWorkRng
If Not pRng.Font.Strikethrough Then
xOut = xOut + pRng.Value
End If
Next
ExcStrike = xOut
End Function
pnuts
  • 54,806
  • 9
  • 74
  • 122
arbitel
  • 321
  • 6
  • 22

1 Answers1

4

For the sake of an answer:

The Long data type contains integer numbers.

per OP:

solution was to change 'As Long' to 'As Single'

I suppose I should add a little detail about Single

Holds signed IEEE 32-bit (4-byte) single-precision floating-point numbers ranging in value from -3.4028235E+38 through -1.401298E-45 for negative values and from 1.401298E-45 through 3.4028235E+38 for positive values. Single-precision numbers store an approximation of a real number.

pnuts
  • 54,806
  • 9
  • 74
  • 122