# VBA/UserForm: Find max, min value and less than 4000 in selected listbox items



## ZerIo_0I (Dec 20, 2022)

Hello all
I really need your help as the topic title says I need to find the minimum, maximum, less than 4000 among the selected listbox items.




UserForm.xlsmAB1EmployeeSalary2Gilmore34403Stone67804Horton102445Rice54326McDaniel205447Fowler123228Paul54409Burns765610Robertson4568UserForm
I already have a form, but I have no idea how to do those operations
Thank you in advance


----------



## Flashbond (Dec 21, 2022)

I don't know your object names. So you have to replace them with the items on your form:


```
Private Sub CalculateButton_Click() 'Must be original button name
  Dim listboxItems() As Long
  Redim listboxItems(ListBox1.ListCount-1) 'Must be original Listbox Name
  For i = 0 To ListBox1.ListCount-1
    listboxItems(i) = Val(ListBox1.List(i ))
  Next i
  If MinButton.Value Then 'Must be original radio button name
    TextBox1 = Application.WorksheetFunction.Min(listboxItems)
  End If
  If MaxButton.Value Then 'Must be original radio button name
    TextBox1 = Application.WorksheetFunction.Max(listboxItems)
  End If
  If lessThan400Button.Value Then 'Must be original radio button name
      For i = 0 To ListBox1.ListCount-1
        If listboxItems(i)<4000 Then
          TextBox1 = listboxItems(i)
          Exit For
        End If
    Next
  End If
End Sub
```


----------

