View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default How to get out of loop ????

GetName:
NAreaName = InputBox("Please enter the New Area name. ", "Area Name
Input")
If Len(NAreaName) 18 Then ' check if name exceeds length limit
MsgBox " Proposed name is too long, try again. "
GoTo GetName
End If
For Each cell In Range("AreaNames") ' check if name is in use
If NAreaName = Trim(cell.Value) Then
MsgBox "New name is already in use, try again."
GoTo GetName
End If
Next cell

' confirmation check before proceeding

bMbResponse = MsgBox("You have entered : " & NAreaName & " " & vbCrLf &
_
" Do you want to continue?", vbYesNo)

If bMbResponse = vbNo Then Exit Sub ' decide you did not want to
proceed

' write new name to worksheet
Worksheets("Area").Cells(7, RrC + 1).Value = NAreaName


"Ray Batig" wrote in message
link.net...
I wrote the following code to get a new name . Everything works except my
confirmation check. I have tried several attempts and have not met with
sucess. In all cases, I end up completing the sub when I click the No

button
to BMbResponse. What am I missing? Is there a better way?

Thanks for your help and Merry Christmas.

Ray

Do Until NAreaName < ""

NAreaName = InputBox("Please enter the New Area name. ", "Area
Name Input")
If Len(NAreaName) 18 Then ' check if name exceeds length

limit
MsgBox " Proposed name is too long, try again. "
NAreaName = ""
GoTo loop1:
End If
For Each cell In Range("AreaNames") ' check if name is in use
If NAreaName = Trim(cell.Value) Then
MsgBox "New name is already in use, try again."
NAreaName = ""
GoTo loop1:
End If
Next cell
' confirmation check before proceeding

bMbResponse = MsgBox("You have entered : " & NAreaName & " "

&
vbCrLf & _
" Do you want to continue?", vbYesNo)

If bMbResponse = vbNo Then End ' decide you did not want to
proceed

loop1:
Loop
End If
Unload UserForm2
' write new name to worksheet
Worksheets("Area").Cells(7, RrC + 1).Value = NAreaName

End Sub