I apologize in advance for writing to ask for help if you all think this is a stupid question.
I have a userform with 6 comboboxes and 6 textboxes that I can enter values into.
Combobox1 Textbox1 Combobox2 Textbox2 Combobox3 Textbox3 Combobox4 Textbox4 Combobox5 Textbox5 Combobox6 Textbox6
This question requires knowledge of combinations/permutations.
First i enter a code in one of the comboboxes, and then a total CY in the textbox next to it. Then i click a commandbutton to give me a report. What i'm trying to achieve is to write a code that can look in each of the 6 comboboxes, see if code "131010" exist in some of them, if yes, then add textbox1... while excluding textbox2 (if the code is not in combobox2).
So if only combobox1, 3, 5, 6 have that code, i need to only add textbox1, 3, 5, 6 while excluding textbox4.
So far i have the following code:
If ComboBox1.Value = "131010" Or ComboBox3.Value = "131010" Or ComboBox5.Value = "131010" Or ComboBox7.Value = "131010" Or ComboBox9.Value = "131010" Or ComboBox11.Value = "131010" Then
TextBox59.Value = Val(TextBox6) + Val(TextBox11) + Val(TextBox16) + Val(TextBox21) + Val(TextBox26) + Val(TextBox31)
TextBox52.Value = ComboBox1.Value
Else
or i have found this one code:
For i = 1 To 6
If IsNull(Me.Controls("combobox" & i)) = False Then
if combobox & i="131010" then
textbox59=val(textbox6)+val(textbox & i+5)
End If
Next i
The VBA code is adding all the textboxes and does not recognize when there is different cost code in a combobox. I can see what i'm doing wrong, but i'm not sure how to fix it. Can someone please help me figure out how to fix it? or perhaps propose another alternative? perhaps i need to loop through the comboboxes...i don't know how to do this. Please don't give a negative for this question. I really did researched this at length and could not come up with something.
thank you all in advance.