DEV Community

Andrews
Andrews

Posted on • Originally published at geekexcel.com on

How To Decide what an INPUTBOX is supposed to return using VBA in Excel?

In this article, we will guide you on how to decide what an INPUTBOX is supposed to return using VBA ** in Microsoft Excel. Let’s get them below!! Get an official version of MS Excel from the following link: **https://www.microsoft.com/en-in/microsoft-365/excel

Example

  • Firstly, in the Excel Worksheet, you have to go to the Developer Tab.
  • Then, you need to ** ** select the Visual Basic option under the Code section.

Select Visual Basic
Select Visual Basic

  • Now, you have to copy and paste the code given below.
Sub DecideUserInput()
Dim bText As String, bNumber As Integer
    ' here is the INPUTBOX-function :
    bText = InputBox("Insert in a text", "This accepts any input")
    ' here is the INPUTBOX-method :
    bNumber = Application.InputBox("Insert a number", "This accepts numbers only", 1)
    MsgBox "You have inserted :" & Chr(13) & _
        bText & Chr(13) & bNumber, , "Result from INPUT-boxes"
End Sub

Enter fullscreen mode Exit fullscreen mode
  • After that, you need to save the code by selecting it and then close the window.

Save the Code

  • Again, you have to go to the Excel Spreadsheet , and click on the Developer Tab.
  • You need to choose the Macros option in the Code section.

Choose Macro option
Choose Macro option

  • Now, you have to make sure that your macro name is selected and click the *Run * button.

Run the Code

  • After running the macro, you will receive an input dialog box.

Input dialog box

  • You need to enter the following input in the input dialog box.
**Accepted input:**
0 A formula
1 A number
2 Text
4 A logical value (True or False)
8 A cell reference, e.g. a Range-object
16 An error value, e.g. #N/A
64 An array of values
Enter fullscreen mode Exit fullscreen mode

Insert text

  • Finally, the text have you inserted will insert only numbers as given below.

Output 1

Output 2

A Short Summary

Here, we have explained the step-by-step procedure on how to decide what an INPUTBOX is supposed to return using VBA in Microsoft Excel. Make use of this. Please share your worthwhile feedback in the below comment section. To learn more, check out our website Geek Excel!!

Further Reference:

Oldest comments (0)