PDA

View Full Version : Combine 2 Codes



av8tordude
05-29-2009, 06:59 AM
I have 2 listbox in a userform. The code below is to un-tick all ticked items in both list boxes. The code works well, but in an effort to write effiecient coding, I would combine the two coding into one. Can someone provide some assistance?



With Me.ACLIST
EnableEvents = True
For j = 0 To .ListCount - 1
If j = .ListCount - 1 Then EnableEvents = False
.Selected(j) = False
Call ResetLB
Next
End With
With Me.APPCH
EnableEvents = True
For j = 0 To .ListCount - 1
If j = .ListCount - 1 Then EnableEvents = False
.Selected(j) = False
Next
End With

Bob Phillips
05-29-2009, 07:22 AM
No point. The listcounts could be different which would mean testing in the loop, very inefficient.

You could havce a generic lisbox handler and pass the listbox to that, but I wouldn't bother, and that call throws it anyway.

av8tordude
05-29-2009, 10:08 AM
Thank you Xld for you insight.:friends:

Bob Phillips
05-29-2009, 10:25 AM
No problem, the code is fine, it works, it looks good, no more to do :)

Bob Phillips
05-29-2009, 10:27 AM
One thing I just thought, insteda of loopping all items and testing for the last and turning off events, why not do it like so



With Me.ACLIST
EnableEvents = True
For j = 0 To .ListCount - 1
.Selected(j) = False
Call ResetLB
Next
EnableEvents = False
End With


saves the test