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
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

mikecroom

New Member
Joined
Oct 8, 2010
Messages
47
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"
 

Ruddles

Well-known Member
Joined
Aug 24, 2010
Messages
5,786
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"
 

Ash3154

New Member
Joined
Dec 21, 2010
Messages
6
Guys, thanks for the replies, I decided to go another route, but thank you for getting back to me so quickly.

Thanks,
 

Watch MrExcel Video

Forum statistics

Threads
1,118,164
Messages
5,570,578
Members
412,327
Latest member
KLichter
Top