Show alert when lookup finds more than 10 rows

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. 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.



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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top