How to populate a combo box with filtered data from a named range
Typo in my suggestion:
set wks = worksheets("sheetnamewithtablehere")
set myrng = .range("a2", .cells(.rows.count,"A").end(xlup))
end with
Should have been:
set wks = worksheets("sheetnamewithtablehere")
With Wks
set myrng = .range("a2", .cells(.rows.count,"A").end(xlup))
end with
dan dungan wrote:
Hi Dave,
I pasted your code sample in cboPrimary. There was an orphan "end
with" that I removed. The line below highlights "(.rows" and returns
the error: Invalid or unqualified reference.
I have searched the archives for "Set myRng = .Range" to see if
something was misspelled, but I couldn't figure out the error.
Do you have any suggestions.
Thanks,
Dan
Here's the line that returned the error:
Set myRng = .Range("a2",.Cells(.Rows.Count,"A").End(xlUp))
Private Sub cboPrimary_Change()
Dim wks As Worksheet
Dim myCell As Range
Dim myRng As Range
Set wks = Worksheets("tblContacts")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
With Me.cboSecondary
.RowSource = "" 'can't use .rowsource and .additem!
.Clear
For Each myCell In myRng.Cells
If LCase(myCell.Text) = LCase(Me.cboPrimary.Value) Then
.AddItem myCell.Offset(0, 1) '1 column to the right
End If
Next myCell
End With
End Sub
--
Dave Peterson
|