object variable not set error

jishnu

New Member
Joined
Mar 25, 2019
Messages
15
Rich (BB code):
Sub LoopThroughSheets()
 Dim findRng As Range
 Dim firstRow As Long
 Dim nextRow As Variant
 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)


            nextRow = findRng.row
           
            Call SearchForPKZ(nextRow)
           
      
      End If
      End With




     Next ws
   Next j


End Sub


vba editor is showing error message on the red coloured text above.. pls helppp
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Then you can't use FindNext here, as I said, you have to use Find again with the same parameters.
 
Upvote 0
Thanks a lot for the answers. It helped me so so much. I was able to complete my succesfully. Thanks a lott!!
 
Upvote 0
Glad you were able to sort it out & thanks for the feedback
 
Upvote 0
I have one more doubt. I would be so grateful if anyone can help me.
I am searching for a string in more than 1 worksheet (in a entire workbook with more than 10 sheets) . For this i am looping through all the worksheets to find the results. Is there any way for me to know , IN HOW MANY SHEETS THE VALUE HAS BEEN FOUND?? Precisely, i want to know whether a value is present in 2 sheets.

the code is given below.

Code:
Sub LoopThroughSheets(i)
 Dim findRng As Range
 Dim notFound As Boolean
 
 notFound = True
 
 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
        Column = findRng.Column
        notFound = False
        Set findRng = .UsedRange.Find(MKB_array(j), After:=Cells(firstRow, Column), lookat:=xlPart)
        If Not findRng Is Nothing Then
           CurrentRow = findRng.row
           Call SearchForPKZ(CurrentRow, i)
        End If
       
        Do
       
        Set findRng = .UsedRange.Find(MKB_array(j), After:=Cells(CurrentRow, Column), lookat:=xlPart)
         
        If Not findRng Is Nothing Then
           CurrentRow = findRng.row
           Call SearchForPKZ(CurrentRow, i)
        End If


        Loop While CurrentRow <> firstRow     ' here it goes for first row again at the end of the loop. so it better not to call searchforPKZ wt the first time when we find MKB
      
   End If


      End With


     Next ws
   
   Next j
   
  If notFound Then
  Workbooks(Plannungsdatei).Worksheets("DB").Cells(i, ColOfSYSTT_inPlannung).Interior.ColorIndex = 3 ' red
  End If


End Sub

Thanks a lot again for helping me out so far.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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