InputBox Function in Excel using VBA - ScoreInExcel

Easy way to Learn Excel....

ads
Responsive Ads Here

Post Top Ad

Your Ad Spot

Tuesday 22 August 2017

InputBox Function in Excel using VBA

Untitled Document The InputBox function helps the users to get the values dynamically from the user on run time. Once user enters the value and click OK button then it will perform some task based on the VBA code. We will see this with one example to understand clearly.

Syntax:

InputBox(prompt, [title], [default], [xpos], [ypos], [HelpFile], [Context]) as string Follow the below steps to create a button and display the name in excel using input box method.

Step 1:

Create a button in excel to display the name in cell "C4" as shown in the below picture.


Step 2:

Right click on the button and click view code to get into VBA Editor mode. Copy the below code and paste it in that VBA editor.
Private Sub CommandButton1_Click()
Dim My_Input_Value As Variant
My_Input_Value = InputBox("Enter Your Name", "InputBox Method")
Range("C4").Value = My_Input_Value
End Sub

Step 3:

Now come to the excel sheet where you have button. Click the button it will prompt a box to do something as shown in the below picture.

Step 4:

Enter your name in that box and click OK to complete the process. The typed name will be displayed in your excel sheet now as shown in the below picture.
If you want to change the button name, then go to properties window and change the name as per your requirement. Hope this will clear your IntputBox method using macro. Thanks for visiting the website.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot