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.
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
the code is given below.
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