PDA

View Full Version : Populating userform combo boxes



MattMurdock
2012-08-09, 08:54 PM
Hi I'm having trouble populating a UserForm combo box

Here's my code, any help would be great-


Private Sub ArchiveForm_Initialize()
Dim cPart As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("Calibration Data")
For Each cPart In ws.Range("Archives")
With Me.ComboBox2
.AddItem cPart.Value
.List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
End With
Next cPart
For Each cLoc In ws.Range("Years")
With Me.ComboBox1
.AddItem cLoc.Value
.List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
End With
Next cLoc
End Sub

Ken Puls
2012-08-22, 06:50 AM
Try this:



Private Sub UserForm_Initialize()Dim cPart As Range
Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("Calibration Data")
For Each cPart In ws.Range("Archives")
With Me.ComboBox2
.AddItem cPart.Value
.List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
End With
Next cPart
For Each cLoc In ws.Range("Years")
With Me.ComboBox1
.AddItem cLoc.Value
.List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
End With
Next cLoc
End Sub