Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50099

Can a function be modified to accept a divisor?

$
0
0
Hello,

I asked for and received assistance for the creation of this function. It's #4:

http://www.excelforum.com/excel-prog...html?p=3078063

I've now modified the line: GetTens = CLng(Right(vVal \ 10, 1)) and created several new functions by changing the 10 to 1 or 100 or 1000. It's becoming confusing.

Is it possible to place the divisor into the function call as something like:

Function ADD_POSITIONS(Position,ParamArray cells()) As Double
usage would be: =ADD_POSITIONS(10,A1,A2,A3,A4)

instead of

Function ADD_TENS(ParamArray cells()) As Double
usage would be: =ADD_TENS(A1,A2,A3,A4)

where the 10 would be the divisor? So the 10 would become 1 or 10 or 100 or 1000, etc. If this is possible, it would stop the confusion with using multiple versions of the same function.

Thank you.

Edited to include the original function:

Function ADD_TENS(ParamArray cells()) As Double
' Generic Usage: =ADD_TENS(Cell_1,Cell_2,Cell_3,Cell_4)
' Usage in cell: =ADD_TENS(A1,A2,A3,A4)
Dim n As Long
Dim rCell As Range
Dim dTemp As Double

For n = LBound(cells) To UBound(cells)
If TypeName(cells(n)) = "Range" Then
For Each rCell In cells(n).cells
dTemp = dTemp + GetTens(rCell.Value)

Next rCell
End If
Next n
ADD_TENS = dTemp

End Function
Function GetTens(vVal) As Long
If IsNumeric(vVal) Then
GetTens = CLng(Right(vVal \ 10, 1))
End If
End Function

Viewing all articles
Browse latest Browse all 50099

Trending Articles