populate combo box from worksheet
Maybe...
Option Explicit
Private Sub UserForm_Initialize()
Dim myRng As Range
Dim myCell As Range
'Service.xls has to be open!
With Workbooks("service.xls").Worksheets("sheet1")
Set myRng = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
End With
'can you use the entire range of values?
Me.ComboBox1.List = myRng.Value
'or if you wanted to loop
For Each myCell In myRng.Cells
Me.ComboBox1.AddItem myCell.Value
Next myCell
'or if you wanted to check a value
'and add the item from a different column
For Each myCell In myRng.Cells
If LCase(myCell.Value) = "some value here" Then
Me.ComboBox1.AddItem myCell.Offset(0, 1).Value
Next myCell
End Sub
tracktraining wrote:
Hi All,
I am new to excel vba coding. I hope you can help me out. I have created a
combo box in Userform. Now I need to populate the data. The data is stored in
sheet1 of service.xls file. How can I populate my combo box with the data in
the service.xls file? I would use the .AddItem but there are a lot of data.
Thanks,
Tracktraining
--
Learning
--
Dave Peterson
|