Find Maximum and Minimum Value of specific columns in sheet1

Flexcel22

Board Regular
Joined
Apr 8, 2016
Messages
52
Hi MVPs and Gurus,

I would like to ask a favor if you could direct me on the right path as I am a bit stuck.

I'd like to write a macro to find maximum and minimum in specific columns of sheet1 and return the value to corresponding textboxes on a userform.

For example

I had a userform with a button called "Refresh Data" and several textboxes for each columns maximum and minimum.

When I click the button
Column 1 Maximum = textbox1, Column2 Maxmum = Textbox2, Column3 Maximum = Textbox3 and continues on to a few more columns
Column 1 Minimum = TextBox10, Column2 Minimum = Textbox11, etc, etc. I hope you get the picture of what I am trying to do.

Thank you in advance and hope to hear from you
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
and continues on to a few more columns
If you wish for someone to write code that will work for you specifically, then how many columns. A few more is not something we can write code for. It appears that you wish to have this information put into a user form. What name did you give it? Help us to help you by being specific in your request. We may be pretty good at Excel, but we are really poor at mind reading.
 
Last edited:
Upvote 0
If you wish for someone to write code that will work for you specifically, then how many columns. A few more is not something we can write code for. It appears that you wish to have this information put into a user form. What name did you give it? Help us to help you by being specific in your request. We may be pretty good at Excel, but we are really poor at mind reading.

Hi Alan,

Sorry for not specifying complete information.

What I mean by "and it continues on to few more columns" is the remaining columns continues to column 9. And each column number correspond to textbox number. eg Maxmum for column 5 is for textbox5, Maximum for column 6 is for textbox6, 7 to 7, 8 to 8 and 9 to 9. The number of minimum is the same with maximum. Nine textboxes too, starting from textbox10.

I havent written a code but that's what I am trying to do here. I needed a code to do such a thing. All I have is a userform with a button run and several textboxes
 
Upvote 0
Untested, but try this, it will load then textboxes on startup
Code:
Private Sub UserForm_Initialize()

    Dim Cnt As Long

     For Cnt = 1 To 9
        Controls("TextBox" & Cnt).Value = WorksheetFunction.Max(Columns(Cnt))
        Controls("TextBox" & Cnt + 9).Value = WorksheetFunction.Min(Columns(Cnt))
    Next Cnt

End Sub
This needs to go in the Userform module
 
Upvote 0
Solution
Thank You Fluff,

Your code perfectly worked.

Thanks buddy and hope to see more of your solutions in my future threads.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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