K
Kate
Hi, I have modified Dave Peterson's lovely 'mvlookup' function for
returning multiple objects from a lookup function, to instead return a
range rather than a concatenated string. I renamed it 'rvlookup'.
I initially encountered an object error as I attempted to set the
function's return value to a range rather than a string. After adding
a 'set' in front of the final return value statement, no more error there.
However, when I invoke the function code to set a rowsource property
of a combobox TO this range, I get the 'type mismatch error 13" message.
Rvlookup has inputs of a lookup value, the array in which to look, and
which column contains the values to be returned. These are the
essential code snippets:
Public Function rvlookup(lookupValue As Variant, tableArray As Range,
colIndexNum As Long) As Range
Dim myRes() As Variant
Dim i As Long
.....(code that sets myres(i) to all the matching values in the lookup
range. The code below then places those value into cells in a worksheet.)
'select Lookups worksheet
Sheets("lookups").Select
'select starting cell to paste mill codes
Range("l2").Select
For i = LBound(myRes) To UBound(myRes)
ActiveCell.Value = myRes(i)
ActiveCell.Offset(1, 0).Select
Next i
Set rvlookup = ActiveSheet.Range("l2:l" & (i - 1))
End Function
The above function is invoked when a value is chosen from a combobox
(cboCompany), and the rowsource of a second combobox (cboMills) is
being set to the range that is returned by rvlookup:
Sub cboCompany_Change()
frmMills.cboMills.RowSource = _
rvlookup(Worksheets("data").Range("c3"), _
Worksheets("Lookups").Range("C2:J139"), 2).Value
frmMills.cboMills.ControlSource = Worksheets("data").Range("d1")
frmMills.Show
End Sub
I get the type mismatch error when attempting to set the rowsource of
the cboMills combobox. Apparently it doesn't recognize that this is a
range? I added the '.value' at the end of the rowsource setting but
that didn't help.
Any ideas? Thanks to all,
Kate
returning multiple objects from a lookup function, to instead return a
range rather than a concatenated string. I renamed it 'rvlookup'.
I initially encountered an object error as I attempted to set the
function's return value to a range rather than a string. After adding
a 'set' in front of the final return value statement, no more error there.
However, when I invoke the function code to set a rowsource property
of a combobox TO this range, I get the 'type mismatch error 13" message.
Rvlookup has inputs of a lookup value, the array in which to look, and
which column contains the values to be returned. These are the
essential code snippets:
Public Function rvlookup(lookupValue As Variant, tableArray As Range,
colIndexNum As Long) As Range
Dim myRes() As Variant
Dim i As Long
.....(code that sets myres(i) to all the matching values in the lookup
range. The code below then places those value into cells in a worksheet.)
'select Lookups worksheet
Sheets("lookups").Select
'select starting cell to paste mill codes
Range("l2").Select
For i = LBound(myRes) To UBound(myRes)
ActiveCell.Value = myRes(i)
ActiveCell.Offset(1, 0).Select
Next i
Set rvlookup = ActiveSheet.Range("l2:l" & (i - 1))
End Function
The above function is invoked when a value is chosen from a combobox
(cboCompany), and the rowsource of a second combobox (cboMills) is
being set to the range that is returned by rvlookup:
Sub cboCompany_Change()
frmMills.cboMills.RowSource = _
rvlookup(Worksheets("data").Range("c3"), _
Worksheets("Lookups").Range("C2:J139"), 2).Value
frmMills.cboMills.ControlSource = Worksheets("data").Range("d1")
frmMills.Show
End Sub
I get the type mismatch error when attempting to set the rowsource of
the cboMills combobox. Apparently it doesn't recognize that this is a
range? I added the '.value' at the end of the rowsource setting but
that didn't help.
Any ideas? Thanks to all,
Kate