Search code examples
excelexcel-formulaexcel-2013vba

Single cell sum and blank cell


I'm using this macro to sum individual numbers, separated by comma, in single cell

Function Individual(R As Range) As Double
   Individual = Evaluate(Replace(R.Value, ",", "+"))
End Function

Function looks like this =Individual(XY), where XY is "source" cell where individual numbers are written.

How to modify macro to write 0 to "target" cell when "source" cell is blank?


Solution

  • Function Individual(R As Range) As Double
      if len(r.value) > 0 then
        Individual = Evaluate(Replace(R.Value, ",", "+"))
      else
        Individual = 0
      end if
    End Function