Find Function Error 91

nirmalachr

New Member
Joined
Nov 25, 2013
Messages
26
Hi,

I am using the following code to find values in particular column, when the entered value is available in the particular column it is showing the particular rows in the list box. Now the problem is that if the value is not available it returning to the error 91.

Private Sub CommandButton1_Click()
ListBox1.Clear
Dim cell As Range
Dim saddr As String
Dim sh As Worksheet
Set sh = ActiveWorkbook.Sheets("ENTRY")
Set cell = sh.Range("G2:G10000").Find(What:=TextBox1.Text, after:=Range("G10000"), LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False)
If Not cell Is Nothing Then saddr = cell.Address
Do
With ListBox1
.AddItem cell.Offset(0, -3).Value & " " & cell.Offset(0, -2).Value & " " & cell.Offset(0, -1).Value & " " & cell.Offset(0, 0).Value & " " & cell.Offset(0, 1).Value & " " & cell.Offset(0, 2).Value & " " & cell.Offset(0, 4).Value & " " & cell.Offset(0, 5).Value
'.List(ListIndex, 2) = cell.Offset(0, 4).Value
'.List(ListIndex, 3) = cell.Offset(0, 4).Address
End With
Set cell = sh.Range("G2:G10000").FindNext(cell)
Loop While cell.Address <> saddr
MsgBox ("Thank you")
End Sub

Kindly help me out from this issue
 
Maybe this. :cool:
Code:
Private Sub CommandButton1_Click()
ListBox1.Clear
Dim cell As Range
Dim saddr As String
Dim sh As Worksheet
Set sh = ActiveWorkbook.Sheets("ENTRY")
Set cell = sh.Range("G2:G10000").Find(What:=TextBox1.Text, after:=Range("G10000"), LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByColumns, searchdirection:=xlNext, MatchCase:=False)
If Not cell Is Nothing Then
saddr = cell.Address
Do
With ListBox1
.AddItem cell.Offset(0, -3).Value & " " & cell.Offset(0, -2).Value & " " & cell.Offset(0, -1).Value & " " & cell.Offset(0, 0).Value & " " & cell.Offset(0, 1).Value & " " & cell.Offset(0, 2).Value & " " & cell.Offset(0, 4).Value & " " & cell.Offset(0, 5).Value
'.List(ListIndex, 2) = cell.Offset(0, 4).Value
'.List(ListIndex, 3) = cell.Offset(0, 4).Address
End With
Set cell = sh.Range("G2:G10000").FindNext(cell)
Loop While cell.Address <> saddr
MsgBox ("Thank you")
End If
End Sub
 
Upvote 0

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