Question

(EXCEL VBA)Write a program for a beauty store that uses an InputBox to ask the guest...

(EXCEL VBA)Write a program for a beauty store that uses an InputBox to ask the guest for a membership code. Embed this in a Do loop so that the user has to keep trying until the result is a valid membership code that starts with “Beauty” (case insensitive) and is followed by 4 digits with the final digit equal to either 6 or 8. Then use a message box to display the input promotion code and inform the user that the code has been applied. Hint: You can check if a character is a digit by seeing if it is >= “0” and if it is <= “9” (the quotation marks are needed).

Homework Answers

Answer #1

Hi,

Insert this code in any excel VBA editor module (ALT +F11 >> Module > Insert)

Sub LoopInputBoxCheck()
'Scope: An example of how to keep looping an input box until a valid answer is entered
'
Dim InputQuestion As String
Dim myAnswer As Variant
Dim X As Boolean

X = False


'Question to pose to the user
  InputQuestion = "Please enter Mebmership code" & vbNewLine _
    & "(Hint: It starts with Beauty)"

'Keeping looping until you get a valid answer to your question
  Do
    'Retrieve an answer from the user
      myAnswer = Application.InputBox(InputQuestion, "Your Answer")
    
      If Left(myAnswer, 6) = "Beauty" Then If Len(myAnswer) = 10 Then If Right(myAnswer, 1) = 6 Or Right(myAnswer, 1) = 8 Then X = True
            
      If X = True Then MsgBox ("Code " & myAnswer & "has been applied")
      
      If X = True Then Exit Sub
          
      
      
                
          
    Loop While myAnswer <= 0 Or myAnswer > 120



End Sub
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions