Answered! The last time this question was asked it was wrong. An InputBox returns a string – whatever the user enters in the…

The last time this question was asked it was wrong. An InputBox returns a string – whatever the user enters in the box. However, it returns a blank string if the user enters nothing and clicks on OK or on Cancel. Write a sub that uses an InputBox to ask the user for a product code. Embed this in a Do Loop so that the user has to keep trying until the result is not a blank string.

Expert Answer

 Below are the three implementation of do untill loop that I know.

Private Sub CommandButton1_Click()
Dim amount As Variant
amount = “”
‘*************Implementation 1**************************
Do
amount = InputBox(“Please enter the Product Code”)
Cells(1, 2).Value = amount
Loop Until amount <> “”

‘*************Implementation 2**************************
Do
amount = InputBox(“Please enter the Product Code”)
Cells(1, 2).Value = amount
Loop While amount <> “”

‘**************Implementation 3*************************
amount = InputBox(“Please enter the Product Code”)
Do While amount <> “”
amount = InputBox(“Please enter the Product Code”)
Cells(1, 2).Value = amount
Loop

End Sub

VBA code-

Private Sub CommandButton1_Click()
Dim amount As Variant
amount = “”
Do
amount = InputBox(“Please enter the Product Code”)
Cells(1, 2).Value = amount
Loop While amount <> “”
End Sub

Screenshot-

Answered! The last time this question was asked it was wrong. An InputBox returns a string - whatever the user enters in the... 1

Thanks and Regards,

Vinay Prakash Singh

Still stressed from student homework?
Get quality assistance from academic writers!