kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hi I have this lookup code and I need a little adjustments to do my bidding.
I want to avoid loading the listbox when the data exceeds 10 rows.
I have been starring at it for a while. I can't figure out what to place and where to place it.
I want to avoid loading the listbox when the data exceeds 10 rows.
I have been starring at it for a while. I can't figure out what to place and where to place it.
Code:
Sub Lookup()
Me.lstView.ColumnCount = 6
Dim myArray As Variant
myArray = [c7].Resize(, Me.lstView.ColumnCount + 1).Value
Me.lstView.List = myArray
Me.lstView.Clear
term = Me.CmbClass.Value
With Sheets(term).Range("C7:C1007")
Set rngFind = .Find(what:=Me.Rw2.Text, After:=Sheets(term).[C1007], LookIn:=xlValues, lookat:=xlWhole, SearchDirection:=xlNext)
If Not rngFind Is Nothing Then
strFirstFind = rngFind.Address
Do
If rngFind.Row > 1 Then
Me.lstView.AddItem rngFind.Offset(0, -1).Text
For i = 1 To 5
Me.lstView.List(Me.lstView.ListCount - 1, i) = rngFind.Offset(0, i - 1).Text
Next i
End If
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstFind
End If
End With
End Sub