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
 

VoG

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

Forum statistics

Threads
1,082,114
Messages
5,363,244
Members
400,722
Latest member
DrewPop24

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top