+ Reply to Thread
Results 1 to 1 of 1

Maximum function

Hybrid View

  1. #1
    Registered User
    Join Date
    05-17-2011
    Location
    Cape Town, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    1

    Maximum function

    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
    Last edited by Leith Ross; 05-18-2011 at 01:07 AM. Reason: Added Code Tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1