Consulting

Results 1 to 3 of 3

Thread: Finding Highest valued TextBox?

  1. #1
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location

    Finding Highest valued TextBox?

    Hi, does anyone know how to examine a userform that has 12 textboxes on it each with a value in it?....the examination would be to find the highest value return the value and which box it resides in........if there were two or more values the same return all those values and the boxes they reside in.

    I have an idea that they would need to be manipulated into some sort of array but have no idea how to do it or how to return the result....basically i have nothing!

    Any ideas?

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  2. #2
    Simon

    Put a button on your form, and include the following code

    [vba]
    Private Sub CommandButton1_Click()
    Dim arr(12, 2)
    i = 1
    For Each cnt In Me.Controls
    If TypeName(cnt) = "TextBox" Then
    arr(i, 1) = cnt.name
    arr(i, 2) = Val(cnt.Text)
    i = i + 1
    End If
    Next cnt

    holder = WorksheetFunction.Max(WorksheetFunction.Index(arr, 0, 3))
    For i = 1 To 12
    If arr(i, 2) = holder Then
    MsgBox arr(i, 1) & ", " & arr(i, 2)
    End If
    Next i

    End Sub
    [/vba]

    I've hard coded the array to have 12 lines based on your post.

    HTH

    Tony

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Tony thanks very much works a treat!

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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