preselecting in combo box
Hi Anand,
In the Userform module, try something
like:
'===========
Private Sub UserForm_Initialize()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim rCell As Range
Dim Res As Variant
Dim arr As Variant
Set WB = ThisWorkbook '<<===CHANGE
Set SH = WB.Sheets("Sheet1") '<<===CHANGE
With SH
Set Rng = .Range("A1:A10") '<<===CHANGE
Set rCell = .Range("B3") '<<===CHANGE
End With
arr = Rng.Value
Res = Application.Match(rCell.Value, arr, 0)
With Me.ComboBox1
.List = arr
If Not IsError(Res) Then
.ListIndex = Res - 1
End If
End With
End Sub
'<<==========
---
Regards.
Norman
"Anand" wrote in message
...
On May 22, 3:53 pm, merjet wrote:
Private Sub UserForm_Initialize()
Dim iCt As Integer
iCt = -1
For Each c In Range(ComboBox1.RowSource)
iCt = iCt + 1
If c = Range("B11") Then
ComboBox1.ListIndex = iCt
Exit Sub
End If
Next c
End Sub
The above assumes the RowSource property has been set and the sheet
with the relevant B11 is the ActiveSheet.
Hth,
Merjet
I have multiple combo boxes to be filled in with such data. In some
cases, the data comes from a defined RowSource. For some it is
populated through some set of cells. How can I achieve same results
with the comboBox populated using addItem()?
Thanks,
Anand.
|