PDA

View Full Version : adding entries into combobox with code



paul_pearson
07-23-2013, 11:14 AM
Hi

I have added an extra 2 bits of code for the userform.Unfortunately i am unable to get this to work.What errors have i made please as there is no list in the 2 dropdown box?

Also is it possible to have the X close button in the top right hand corner disabled so that if it is selected nothing happens.Only selecting the close button shutdown the userform.

Thanks again

Paul


https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg.9h5lFRmix1R9h78GftO_ iE (https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgwviLabd7r_3KpP6wh4AaABAg.9h5lFRmix1R9h78GftO_ iE)
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h77HSGDH 4A (https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h77HSGDH 4A)
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h76fafzc EJ (https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h76fafzc EJ)
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h759YIjl aG (https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h759YIjl aG)
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h74pjGcb Eq (https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg.9h740K6COOA9h74pjGcb Eq)
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg (https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgyG714V_k7odQMrTz14AaABAg)
https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgzJJUDVv2Mb6YGkPYh4AaABAg.9h5uPRbWIZl9h7165DZd jg (https://www.youtube.com/watch?v=2oT4qrHmDMY&lc=UgzJJUDVv2Mb6YGkPYh4AaABAg.9h5uPRbWIZl9h7165DZd jg)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

Transformer
07-23-2013, 01:01 PM
You have used userform1_Initialize and userform2_Initialize procedures to add items to Combobox2 and combobox3 but you didn't call them anywhere. Either write that code in UserForm_Initialize procedure or call these two procedures in UserForm_Initialize procedure.

Suggestion:
To fill the comboboxes,you add items to an array and then loop through the array to add items.You dont need to do that.It can be done in a single line.
e.g.

ComboBox2.List = Worksheets("Data").Range("B2:B15").Value

You can use the following snippet to disable the X button:


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
End If
End Sub

Addendum:
If you want to avoid all the loops while filling the comboboxes than you can use the following code:


Private Sub UserForm_Initialize()

ComboBox1.List = Evaluate("IF(ROW(1:15),TEXT(NOW()-8 + ROW(1:15),""mm-dd-yyyy""))")
ComboBox2.List = Worksheets("Data").Range("B2:B15").Value
ComboBox3.List = Worksheets("Data").Range("C2:C5").Value

End Sub