View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_2531_] Rick Rothstein \(MVP - VB\)[_2531_] is offline
external usenet poster
 
Posts: 1
Default Sum the first character in a range

As long as your numbers are whole numbers or, if they are floating point
numbers, as long as your decimal point is a dot, you can use this
function...

Function SumRow(RowNumber As Long) As Double
Dim C As Range
Dim X As Long
Dim LastCol As Long
With Worksheets("Sheet1")
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
For X = 1 To LastCol
SumRow = SumRow + Val(.Cells(1, X).Value)
Next
End With
End Function

If there is the possibility that floating point values may be encountered
and the decimal point could be either a dot or a comma, then this variation
can be used...

Function SumRow(RowNumber As Long) As Double
Dim C As Range
Dim X As Long
Dim LastCol As Long
With Worksheets("Sheet1")
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
For X = 1 To LastCol
SumRow = SumRow + Val(Replace(.Cells(1, X).Value, ",", "."))
Next
End With
End Function

Rick



"John LR" wrote in message
...
Could some body Please help.
I need to sum the first number in each cell of my Range EG:
A1 B1 C1
2a 6c 2we = 10

Dim myrange1 As Range
Dim a As Integer
Set myrange1 = Range(Selection.EntireRow.Cells(1, 1), Selection)
a = Application.WorksheetFunction.Sum(myrange1)
MsgBox a

Any help much appreciated