Find function inside a find function loop
Can anybody tell me if I have anything wrong with this code. The Find function on the outside loop isn't finding what it's supposed to and it may be something to do with conflicting with the inside find function.
the code looks inside the 1st workbook to match variable Str and then inside the 2ndworkbook it should put the title of the row it has found the match - It calls us a function to do this. It also should count all the matches and add them together one by one in a loop. It does this loop for each sheet in the 2nd workbook. Str also changes twice from "F" to "FU".
The code below is part of a much larger code so I have put where I thought the error might be.
For Each sht In WKBTemp.Worksheets
d = d + 1
'MsgBox ("Sheet " & sht.Name)
WSNew.Cells(1, col).Formula = sht.Name
WSNew.Cells(1, col + 1).Formula = sht.Name
WSNew.Cells(2, col).Formula = "F"
WSNew.Cells(2, col + 1).Formula = "FU"
Str = "F"
For i = 1 To 2
Set c = sht.Cells.Find(Str, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not c Is Nothing Then
firstAddress = c.Address
Do
MsgBox ("Row of Failure = " & c.Row)
MsgBox (i)
If c.Row > 9 Then
tempval = sht.Cells(c.Row, 4).Value
Set k = WSNew.Cells.Find(tempval, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
InputData c, i, WSNew, k, col, tempval, output
Set k = Nothing
End If
Set c = sht.Cells.FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
Str = "FU"
E = 0
'MsgBox ("Now FU")
Next
col = col + 2
Next sht
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago