Do Loop -- Seems to be going in an Endless Loop

Ash3154

New Member
Joined
Dec 21, 2010
Messages
6
If the Input Entry is a "C" or a "H" then True, otherwise all other entries are False. Even though I Type "C" or "c" it keeps going into a loop. Where am I going wrong? I even tried changing Do While phonetype <> "C" And phonetype <> "c"

Dim phonetype As String
Do While phonetype <> "C" Or _
phonetype <> "c" Or _
phonetype <> "H" Or _
phonetype <> "h" Or _
phonetype = NullString Or _
phonetype = "Select Letter"

phonetype = InputBox(Prompt:="Which Number do you wish to provide Cell or Home ? " _
& vbNewLine & vbNewLine & "SELECT Letter" & vbNewLine _
& vbNewLine & "C = Cell Phone " & vbNewLine _
& vbNewLine & "H = Home Phone" & vbNewLine, _
Title:="ROOM TYPE", Default:="Select Letter")
MsgBox (phonetype & " " & " This is the first MSGBOX")
phonetype = phonetype
MsgBox (phonetype & " " & " This is the 2nd MSGBOX")
MsgBox (" You MUST select a Letter ! ")
Loop


Select Case phonetype

Case "C", "c"
'Input Cell Phone
mycell.Select 'currently sitting at the zipcode cell
ActiveCell.Offset(2, 0).Select
Set mycell = ActiveCell.Offset(0, 0) 'currently sitting at the Cell Phone cell
Selection.NumberFormat = "[<=9999999]###-####;(###) ###-####"
mycell.Value = InputBox("what is the Guest CELL Phone? ", _
Title:="CELL-PHONE", Default:=mycell.Value)

phonetype = MsgBox(Prompt:="Does the customer want to provide Home Number ?", _
Buttons:=vbYesNo)
If phonetype = vbYes Then
ActiveCell.Offset(-1, 0).Select
Set mycell = ActiveCell.Offset(0, 0) 'currently sitting at the Home Phone cell
Selection.NumberFormat = "[<=9999999]###-####;(###) ###-####"
mycell.Value = InputBox("what is the Guest Home Phone? ", _
Title:="HOME-PHONE", Default:=mycell.Value)
'ActiveCell.Offset(1, 0).Show
ActiveCell.Offset(1, 0).Select
Set mycell = ActiveCell.Offset(0, 0) '
MsgBox (mycell.Value & "Not Sure where I am at")
Else
GoTo DL:
End If

Case "H", "h"

'Input Home Phone
mycell.Select 'currently sitting at the zipcode cell
ActiveCell.Offset(1, 0).Select
Set mycell = ActiveCell.Offset(0, 0) 'currently residing at the home phone cell
'MsgBox (mycell.Value & " Should be Home Number")
Selection.NumberFormat = "[<=9999999]###-####;(###) ###-####"
mycell.Value = InputBox("what is the Guest Home Phone? ", _
Title:="HOME-PHONE", Default:=mycell.Value)

phonetype = MsgBox(Prompt:="Does the customer want to provide Cell Number ?", _
Buttons:=vbYesNo)
If phonetype = vbYes Then
ActiveCell.Offset(1, 0).Select
Set mycell = ActiveCell.Offset(0, 0) 'currently sitting at the Cell Phone cell
'MsgBox (mycell.Value & "The Customer said yes to provide cell # after givng home number")
Selection.NumberFormat = "[<=9999999]###-####;(###) ###-####"
mycell.Value = InputBox("what is the Guest CELL Phone? ", _
Title:="CELL-PHONE", Default:=mycell.Value)

Else
Set mycell = ActiveCell.Offset(1, 0) ' currently residing at the cell phone cell
'MsgBox (mycell.Value & " Customer decided not to give cell number after getting home number")
ActiveCell.Offset(1, 0).Select
End If

End Select
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Possibly this but there are other errors in the code

Code:
Dim phonetype As String
phonetype = InputBox(Prompt:="Which Number do you wish to provide Cell or Home ? " _
& vbNewLine & vbNewLine & "SELECT Letter" & vbNewLine _
& vbNewLine & "C = Cell Phone " & vbNewLine _
& vbNewLine & "H = Home Phone" & vbNewLine, _
Title:="ROOM TYPE", Default:="Select Letter")
Do While phonetype <> "C" And _
phonetype <> "c" And _
phonetype <> "H" And _
phonetype <> "h" And _
phonetype = vbNullString And _
phonetype = "Select Letter"

phonetype = InputBox(Prompt:="Which Number do you wish to provide Cell or Home ? " _
& vbNewLine & vbNewLine & "SELECT Letter" & vbNewLine _
& vbNewLine & "C = Cell Phone " & vbNewLine _
& vbNewLine & "H = Home Phone" & vbNewLine, _
Title:="ROOM TYPE", Default:="Select Letter")
MsgBox (phonetype & " " & " This is the first MSGBOX")
phonetype = phonetype
MsgBox (phonetype & " " & " This is the 2nd MSGBOX")
MsgBox (" You MUST select a Letter ! ")
Loop
 
Upvote 0
It is to do with logic of your Do While,

Code:
[SIZE=1]Do While phonetype <> "C" Or _[/SIZE]
[SIZE=1]phonetype <> "c" Or _[/SIZE]
[SIZE=1]phonetype <> "H" Or _[/SIZE]
[SIZE=1]phonetype <> "h" Or _[/SIZE]
[SIZE=1]phonetype = NullString Or _[/SIZE]
[SIZE=1]phonetype = "Select Letter"[/SIZE]

This says "keep looping" whilst either:
1 Phonetype is not equal to "C"
2 or not equal to "c"
etc

For whatever value of phonetype, one of those conditions is true. So you keep looping.

Replacing And with Or may be what you want

Or change "while" to "until"
 
Upvote 0
Code:
[B][COLOR=red]Do While[/COLOR][/B] phonetype <> "C" And _
phonetype <> "c" And _
phonetype <> "H" And _
phonetype <> "h" And _
[COLOR=red][B]phonetype = vbNullString And _
phonetype = "Select Letter"
[/B][/COLOR]
This will always evaluate to False because phonetype can never equal vbNullString and "Select Letter".

Don't you just want:-
Code:
Do Until phonetype = "C" Or _
phonetype = "c" Or _
phonetype = "H" Or _
phonetype = "h"
?

Because if it's "C", "c", "H" or "h", it can't be vbNullString or "Select Letter".

Or:-
Code:
Do Until Ucase(phonetype) = "C" Or Ucase(phonetype) = "H"
 
Upvote 0
Guys, thanks for the replies, I decided to go another route, but thank you for getting back to me so quickly.

Thanks,
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top