VBA code to find min, max, <4000

Gaurur

New Member
Joined
Dec 21, 2022
Messages
4
Platform
  1. Windows
I need code that can output min, max, <4000 result among selected list "items" for this form:


1671611317685.png


Thanks in advance
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi
And welcome
Not sure if I well understand your request
Try
VBA Code:
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
 
Upvote 0
This appears to be exactly the same as this question, but from a different user account. Please explain.
 
Upvote 0
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
 
Upvote 0
Then I will respectfully suggest that you are not going to learn much by simply getting other people to do your work... ;)
 
Upvote 0
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😀.
 
Upvote 0
Hi
And welcome
Not sure if I well understand your request
Try
VBA Code:
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
Thanks
Everything works, only you need to look for these values among several selected ones, for example, like this:
1671632552221.png

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
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,844
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top