Error while using FindNext function

Status
Not open for further replies.

jishnu

New Member
Joined
Mar 25, 2019
Messages
15
I am trying to find the multiple row numbers in which a particular value is found inside.
In the code shown below, the red coloured line shows an error

Rich (BB code):
Rich (BB code):
Rich (BB code):
Sub LoopThroughSheets()
Dim findRng As Range
Dim firstRow As Long
Dim row As Long
Dim allFinds As String
Dim numberOfRowsWithSameMKB As Integer

Workbooks(SYSDatei).Activate


For j = 0 To SizeOfMKB_array - 1
For Each ws In Workbooks(SYSDatei).Worksheets
wsName = ws.Name
With Workbooks(SYSDatei).Worksheets(wsName)


Set findRng = .UsedRange.Find(MKB_array(j), lookat:=xlPart)


If Not findRng Is Nothing Then
firstRow = findRng.row
MsgBox firstRow
Call SearchForPKZ(firstRow)

Do


Set findRng = .UsedRange.FindNext(findRng)
If Not findRng Is Nothing Then Call SearchForPKZ(findRng.row)

Loop While Not findRng Is Nothing And findRng.row <> firstRow


rowArray = Split(allFinds, ",")

numberOfRowsWithSameMKB = UBound(rowArray)



End If
End With

and if i remove ' And findRng.row <> firstRow ' , it works but loops infinitely which is not what i wanted :laugh: So it means only this portion has an issue.

Can anyone help me please !!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Does SearchForPKZ delete anything?
 
Upvote 0
What is the Error?
You probably get it when there is no match so at this moment findRng is nothing then trying to get the row number of a non existing object results in an error .
 
Last edited:
Upvote 0
Hii bobsan42 , you are right ! .. there was no match . but how will write that code then ! i am so confused
 
Upvote 0
This appears to be a duplicate of this thread, so I'm closing this one.

Please also note, and follow, the forum rules on cross-posting.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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