Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
The code below should work for you it uses pretty much the same idea as your code only using a single loop rather than nesting another loop inside the initial loop. I personally find it easier to keep loops simple as the more complex they get and the more nesting is used it becomes hard to know where you are while you are debugging your code. The main problem with you loops are that the first loop will run for ever as cnt will always be 3 due to the fact it is incremented in the inner loop this is what makes it seem as excel has locked up, it is actually running the loop endlessly you can stop the loop from running by using the Ctrl + Break keystroke to break the running code. Also worth a mention is that without an exit of the loops after the correct name is found the inner loop will continue to check the rest of the combobox contents which is unnecessary. i = False NewName = TxtFirstName & "," & TxtLastName cnt = 0 Do While i = False And cnt <= CboNames.ListCount - 1 If CboNames.List(cnt) = NewName Then MsgBox NewName & " Is already on the list" i = True Else cnt = cnt + 1 End If Loop Steve |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Testing each cell for error | Excel Programming | |||
Variable ComboBox on Userform | Excel Programming | |||
Testing for error : was 2nd Occurence | New Users to Excel | |||
testing more than one variable in an if statement | Excel Discussion (Misc queries) |