# VBA code to find min, max, <4000



## Gaurur (Dec 21, 2022)

I need code that can output min, max, <4000 result among selected list "items" for this form:







Thanks in advance


----------



## mohadin (Dec 21, 2022)

Hi
And welcome
Not sure if I well understand your request 
Try

```
Private Sub calculate_Click()
Dim x
Dim i&
ReDim A(0 To ListBox1.ListCount - 1)
For i = 0 To ListBox1.ListCount - 1: A(i) = ListBox1.List(i, 1): Next
      If Me.OptionButton1.Value = True Then TextBox1.Value = WorksheetFunction.max(A)
      If Me.OptionButton2.Value = True Then TextBox1.Value = WorksheetFunction.min(A)
      If Me.OptionButton3.Value = True Then
    For i = 0 To UBound(A)
         If A(i) < 4000 Then x = A(i)
    Next
    TextBox1.Value = x
      End If
End Sub
```


----------



## RoryA (Dec 21, 2022)

This appears to be exactly the same as this question, but from a different user account. Please explain.


----------



## Gaurur (Dec 21, 2022)

RoryA said:


> This appears to be exactly the same as this question, but from a different user account. Please explain.


Hello
The last topic was probably left by my classmate from the university, we have the same tasks with him, and he also advised me to write here.  So please don't think anything bad


----------



## RoryA (Dec 21, 2022)

Then I will respectfully suggest that you are not going to learn much by simply getting other people to do your work...


----------



## Gaurur (Dec 21, 2022)

RoryA said:


> Then I will respectfully suggest that you are not going to learn much by simply getting other people to do your work...


No, just the opposite, I'm here because of a desperate situation for a long time already trying to create this form, and after I received the answer everything cleared up😀.


----------



## Gaurur (Dec 21, 2022)

mohadin said:


> Hi
> And welcome
> Not sure if I well understand your request
> Try
> ...


Thanks
Everything works, only you need to look for these values among several selected ones, for example, like this:



And in the end, so that at the maximum value the result is 5440 and the minimum is 5432
I will be very grateful if you help me a little more


----------

