Lesson#74: Input a name shows its length in the message box


This post will make you learn how to get an input box and show the length of the input text with VBA.

1. Go to Developer Tab.
2. Click on Insert.
3. Select Button (Form Control).

4. Put the button on the worksheet by dragging and putting it on the sheet.
5. Immediately Macro name window will appear.
6. Click on New.

7. There you have to put this Code.
Sub Hello_Click()
Dim Name As String
Name = InputBox(“Input Your name”)
Dim Length As Integer
Length = Len(Name)
MsgBox (Length)
End Sub
Dim Name As String
Name = InputBox(“Input Your name”)
Dim Length As Integer
Length = Len(Name)
MsgBox (Length)
End Sub

8. Click on Run Sub/ UserForm

9. Click on Run at the Macros window.

Now Input any string and click on OK, it will show the length of the string.
Enjoy!!

Leave a Reply