psbrown
MIS
- Oct 16, 2001
- 40
Hi I am new to VBA.
I found this code on this forum and have used it to populate my combo box on a user form in Excel, the problem is when a value is selected the value is not retained in the box it just goes blank.
Any pointers on what I am doing wrong would be appreciated.
Thanks
Paul
Private Sub CmbFirstPer_DropButtonClick()
Dim ListRange As Range, c As Range
' change the below to match your data's range
Set ListRange = ThisWorkbook.Sheets("periodhours").Range("A1:iv1")
With CmbFirstPer
.RowSource = "" ' clear the RowSource, if set
.Clear ' clear ListBox
'.AddItem "All" 'Insert "All" item
For Each c In ListRange
.AddItem c.Value ' Insert the values from ListRange
Next c
'.ListIndex = 0 ' Select the first item ("All")
End With
End Sub
I found this code on this forum and have used it to populate my combo box on a user form in Excel, the problem is when a value is selected the value is not retained in the box it just goes blank.
Any pointers on what I am doing wrong would be appreciated.
Thanks
Paul
Private Sub CmbFirstPer_DropButtonClick()
Dim ListRange As Range, c As Range
' change the below to match your data's range
Set ListRange = ThisWorkbook.Sheets("periodhours").Range("A1:iv1")
With CmbFirstPer
.RowSource = "" ' clear the RowSource, if set
.Clear ' clear ListBox
'.AddItem "All" 'Insert "All" item
For Each c In ListRange
.AddItem c.Value ' Insert the values from ListRange
Next c
'.ListIndex = 0 ' Select the first item ("All")
End With
End Sub