fill listbox, from combobox selection, with closed workbook data

chiabgigi

New Member
Joined
Aug 30, 2009
Messages
48
Hi everyone
with this code, in the combobox, I get the list of sheets in the 'orders' workbook.
I would like that when I select an item, the listbox would be populated with the data present in the A4: J110 range of the sheet, with the name of the selected item.
VBA Code:
Private Sub UserForm_Initialize()
Dim i As Long
Dim Databook As Workbook

Application.ScreenUpdating = False
Set Databook = Workbooks.Open(ThisWorkbook.Path & "/" & "ordini.xlsm")
For i = 1 To Sheets("Foglio1").Range("A100").End(xlUp).Offset(1, 2).Row
   Me.ComboBox1.AddItem Sheets("Foglio1").Cells(i, 2)
Next i

Databook.Save
Databook.Close
Application.ScreenUpdating = True

End Sub

Private Sub ComboBox1_Change()
txtbox1.Value = ComboBox1.Value
End Sub

Private Sub txtbox1_Change() 'textbox whose value initializes the listbox

End Sub

I tried assigning a variable to the combobox value to load the data but it tells me that the source is not valid
Please can you explain to me how I can do it
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about
Rich (BB code):
Dim Databook As Workbook

Private Sub UserForm_Initialize()
Dim i As Long

Application.ScreenUpdating = False
Set Databook = Workbooks.Open(ThisWorkbook.Path & "/" & "ordini.xlsm")
For i = 1 To Sheets("Foglio1").Range("A100").End(xlUp).Offset(1, 2).Row
   Me.ComboBox1.AddItem Sheets("Foglio1").Cells(i, 2)
Next i

Application.ScreenUpdating = True

End Sub

Private Sub ComboBox1_Click()
   Me.ListBox1.List = Databook.Sheets(Me.ComboBox1.Value).Range("A4:J110").Value
End Sub
The line in blue must be at the very top of the module, before any code.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,246
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top