Msgbox loop

J

John

I am trying to establish a macro with a message box to loop through until the
Yes button is pressed. I am using Excel 2003. My code is below:

Sub Test()
Dim PartNum As String

Do
PartNum = InputBox("Enter in Part Number:", "Part Number")
If PartNum = "" Then End
If MsgBox("The Part Number is: " & PartNum, vbYesNo) <> vbYes Then
End If
Loop Until vbYesNo = vbYes

Worksheets("Sheet1").Range("H10").Value = PartNum
End Sub
 
B

Bernard Liengme

Not sure what you are doing with part no, but this solves the Msgbox thing

Sub Test()
Dim PartNum As String

Do
PartNum = InputBox("Enter in Part Number:", "Part Number")
If PartNum = "" Then End
myans = MsgBox("The Part Number is: " & PartNum, vbYesNo)

Loop Until myans = vbYes
Worksheets("Sheet1").Range("H10").Value = PartNum

End Sub

best wishes
 
C

Chip Pearson

Use code like

Dim Res As VbMsgBoxResult
Dim PartNum As String
Do
PartNum = InputBox("Enter part number")
If PartNum = vbNullString Then
Exit Sub
End If
Res = MsgBox("The part number is: " & PartNum, vbYesNo)
Loop Until Res = vbYes

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top