VBA - InputBox

jazmincita

New Member
Joined
Feb 24, 2022
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
Hi there,

I'm a beginner in VBA and I'm trying to write an algorithm that asks the user 5 values and then the system has to display the maximum value written by the user
I thought about doing an Input Box 5 times, with for... next but I'm stuck as I don't know how to display the maximum value.

I'm stuck.

Thanks for your help!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the Board!

You can enter the values into an array, and then take the max value of the array like this:
VBA Code:
Sub MyMax()

    Dim arr(1 To 5) As Long
    Dim i As Long
    
'   Prompt the user 5 times for values
    For i = 1 To 5
        arr(i) = InputBox("Please enter in value number " & i)
    Next i
    
'   Return the maximum value
    MsgBox "The maximum value entered is " & WorksheetFunction.Max(arr)
    
End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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