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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,558
Messages
6,125,504
Members
449,235
Latest member
Terra0013

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