Hello all,
I'm new in VBA. I'm trying to code a maximum function but despite all my effort and reading I can figure out why it's no working.
The function is suppose to work with array as input or a any selected range from the spreadsheet. Simply I trying to reproduce the build in Exel "MAX" function. this is my code
Function Maximum(ParamArray inputs() As Variant)
Dim i, j, k As Integer
Dim rng As Range
If Not IsMissing(inputs()) Then
Maximum = inputs(0)
For i = 1 To UBound(inputs())
If inputs(i) > Maximum Then Maximum = inputs(i)
Next i
ElseIf Not IsEmpty(Selection) Then
Set rng = Selection.Value
Maximum = rng.Cells(1, 1)
For j = 1 To rng.Rows.Count
For k = 1 To rng.Columns.Count
If rng.Cells(j, k) > Maximum Then Maximum = rng.Cells(j, k)
Next k
Next j
End If
End Function
Thank for your helps
I'm new in VBA. I'm trying to code a maximum function but despite all my effort and reading I can figure out why it's no working.
The function is suppose to work with array as input or a any selected range from the spreadsheet. Simply I trying to reproduce the build in Exel "MAX" function. this is my code
Function Maximum(ParamArray inputs() As Variant)
Dim i, j, k As Integer
Dim rng As Range
If Not IsMissing(inputs()) Then
Maximum = inputs(0)
For i = 1 To UBound(inputs())
If inputs(i) > Maximum Then Maximum = inputs(i)
Next i
ElseIf Not IsEmpty(Selection) Then
Set rng = Selection.Value
Maximum = rng.Cells(1, 1)
For j = 1 To rng.Rows.Count
For k = 1 To rng.Columns.Count
If rng.Cells(j, k) > Maximum Then Maximum = rng.Cells(j, k)
Next k
Next j
End If
End Function
Thank for your helps