Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Weird Do...Until behavior...
Below is a snippet from another thread. I have since figured out why the code
was halting, however... whenever the routine runs to add items into the comboboxes, it's not catching the text/values to add... I have textboxes/checkboxes on other pages that use: cText = "My Text" cValue = textbox1.text call AddToCalcBox and it isn't grabbing the values from cText and cValue They are both set to be public so I *think* the code should carry the values back and forth, right? I did notice that new lines are being added into the ComboBoxes, just not the text/value. And another problem is whenever I type "1234" into a textbox, there's 4 blank entries... instead of 1 blank entry. This is really weird... any ideas? Well damn. The code looked good, however... it's halting at "Set Ctrl = projectinfo.multipage1.pages(7).Controls("calcbox" & i)" with the error "Can't find the object specified" - Can't quite figure out why, but I'll kepp pluggin' away... "Incidental" wrote: Hi The code below should help you out or at least give you an idea of where to start. To test add the code to a new module then on the userform add a multipage, on the first page add a checkbox and on the second page add as many comboboxes as you want. 'Add this code to a new module Option Explicit Dim CboBox() As New Class1 Dim Ctrl As Control Dim i, X, Counter As Integer Dim ChckVal Sub AddToAllComboboxes() ChckVal = UserForm1.MultiPage1.Pages(0).CheckBox1.Caption i = 1 For Each Ctrl In UserForm1.MultiPage1.Pages(1).Controls If TypeOf Ctrl Is MSForms.ComboBox Then Set Ctrl = UserForm1.MultiPage1.Pages(1).Controls("ComboBox" & i) Ctrl.AddItem ChckVal i = i + 1 End If Next Ctrl End Sub Sub RemoveFromAllComboboxes() i = 1 For Each Ctrl In UserForm1.MultiPage1.Pages(1).Controls If TypeOf Ctrl Is MSForms.ComboBox Then Set Ctrl = UserForm1.MultiPage1.Pages(1).Controls("ComboBox" & i) Counter = Ctrl.ListCount X = 0 Do While X < Counter Ctrl.ListIndex = (X) If Ctrl.Value = ChckVal Then Ctrl.RemoveItem Ctrl.ListIndex End If X = X + 1 Loop i = i + 1 End If Ctrl.Value = "" Next Ctrl End Sub Then add this code to the click event of the checkbox Private Sub CheckBox1_Click() If UserForm1.MultiPage1.Pages(0).CheckBox1.Value = True Then AddToAllComboboxes Else RemoveFromAllComboboxes End If End Sub Hope this is of some help to you S PS isn't it hard to do IT on the Roof??? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Weird Links Behavior | Links and Linking in Excel | |||
weird macro behavior | Excel Discussion (Misc queries) | |||
Excel weird behavior | Excel Discussion (Misc queries) | |||
Weird clipboard behavior | Excel Programming | |||
Weird behavior of VLOOKUP | Excel Programming |