vba input box and display in cell in Excel

Q156. In Excel, how can I get input from user through a prompt and assign user's input to a cell?

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub InputBoxExample()
  3. ActiveSheet.Range("G2") = InputBox("Enter a test value", "InputBox Example")
  4. End Sub

Result after Macro execution:

a) Line 3 displays a prompt as shown below. The value entered by user is then recorded in cell "G2".

excel vba input box and display in cell

b) Enter a Test value (5 in the example below). Click OK.

excel excel vba input box and display in cell

c) Cell G2 is updated with value entered by user.

excel excel excel vba input box and display in cell

 

You can find similar Excel Questions and Answer hereunder

1) How can I dynamically add series to an existing chart using VBA?

2) How can worksheet functions be accessed in VBA?

3) how do you enter multiple line in a cell in Excel

4) How do i put double quotes in a string in vba in Excel

5) How can I export a WorkSheet as a PDF using VBA?

6) How do I update my DropDown list whenever the sheet is activated?

7) Remove the apostrophe cell text values in Excel

8) How can I identify all cells with Data Validation in my WorkSheet?

9) How to add a link in a sheet to another sheet

10) How do I add a symbol like Triangle / Inverted Triangle for indicating trends in a cell using VBA?

11) How can I update a listbox based on data in a list using VBA?

12) How can I activate a routine when there is a change in value of a cell?

13) How can I set the fill color, font color and set number format of cell to date?

14) One of my formulas has returned an error - how can I trace the error to fix it?

15) How can I add a legend to a chart using VBA?