LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Error testing combobox to variable

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Testing each cell for error [email protected] Excel Programming 2 June 14th 07 04:16 PM
Variable ComboBox on Userform DHallam Excel Programming 2 July 19th 05 12:20 PM
Testing for error : was 2nd Occurence Rodney New Users to Excel 5 April 29th 05 02:59 AM
testing more than one variable in an if statement Charles Excel Discussion (Misc queries) 3 February 22nd 05 06:46 PM


All times are GMT +1. The time now is 03:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"