Excel/VBA - Populate ComboBox with Values

Solved
RussellD Posted messages 60 Status Membre -  
RussellD Posted messages 60 Status Membre -
Hello everyone,

On my Excel 2003 sheet, I have a ComboBox (created via Design mode, not a dropdown list created by Data/Validation). I would like that when I open my Excel sheet, it "loads" with the values from a range of cells (for example, range (Q1:Q4)).
I can't seem to do this; I tried (in VBA):

Private Sub WorkBook_Open() ComboBox1.RowSource = Sheets("Feuil1").Range("Q1:Q4").Value End sub


but it doesn't work.. I tried removing the "", removing the .Value, I messed with this syntax without being able to achieve my goal. Following a suggestion on another forum, I tried this:

Private Sub WorkBook_Open() ComboBox1.List = Sheets("Déperditions").Range("Q1:Q4").Value End Sub


But it doesn't work; it gives me the error "Object Required". Does anyone have an idea to solve this problem?

Thank you in advance for your responses,

Best regards

6 réponses

RussellD Posted messages 60 Status Membre 7
 
Hello pijaku,

thank you very much, your tip works perfectly. However, I have a new problem: the values are correctly stored in the ComboBox, but when I click on it, they do not display in it... Is it related to the event used?
5
pijaku Posted messages 13513 Registration date   Status Modérateur Last intervention   2 771
 
Yes, that's normal. My bad. Use the event: BeforeDropOrPaste
Private Sub ComboBox1_BeforeDropOrPaste(ByVal Cancel As MSForms.ReturnBoolean, ByVal Action As MSForms.fmAction, ByVal Data As MSForms.DataObject, ByVal X As Single, ByVal Y As Single, ByVal Effect As MSForms.ReturnEffect, ByVal Shift As Integer) ComboBox1.Clear Dim i As Integer For i = 1 To 6 ComboBox1.AddItem Cells(i, 8) Next i End Sub
0
RussellD Posted messages 60 Status Membre 7
 
Re

This is not working, the values are not even listed in the combo box anymore.. What is the BeforeDropAndPaste event exactly?
0