Gavint
09-28-2006, 12:41 AM
I've setup a combobox on a Userform to extract data from an Excel worksheet using the below code
Private Sub UserForm_Initialize()
'define name codes
Dim ObjExcel As New Excel.Application
Dim wb As Excel.Workbook
Dim FName As Variant
Dim x As Long
Dim LastRow As Long
FName = "M:\TEMPLATES\NAME_CODES.xls"
Set wb = ObjExcel.Workbooks.Open(FName)
With wb.Sheets(1)
LastRow = .Range("C60").End(xlUp).Row
For x = 1 To LastRow
frmGetName.cbxType.AddItem (.Range("C" & x).Text)
Next x
End With
frmGetName.cbxType.SetFocus
End Sub
All works fine and the combobox is populated OK with the data from Excel.
What is the best way to make sure the user selection is from one of the loaded values (ie not just free text)?
Private Sub UserForm_Initialize()
'define name codes
Dim ObjExcel As New Excel.Application
Dim wb As Excel.Workbook
Dim FName As Variant
Dim x As Long
Dim LastRow As Long
FName = "M:\TEMPLATES\NAME_CODES.xls"
Set wb = ObjExcel.Workbooks.Open(FName)
With wb.Sheets(1)
LastRow = .Range("C60").End(xlUp).Row
For x = 1 To LastRow
frmGetName.cbxType.AddItem (.Range("C" & x).Text)
Next x
End With
frmGetName.cbxType.SetFocus
End Sub
All works fine and the combobox is populated OK with the data from Excel.
What is the best way to make sure the user selection is from one of the loaded values (ie not just free text)?