Davis Henderson
New Member
I can't reproduce your issue with your sample file.
Restart your computer and test.
If issue persist, upload sample file where you can reproduce the error.
Code:
Sub Find_Dat()
Dim datatoFind As String, MySheet As String, FV As String
Dim aSh As Worksheet, fSh As Worksheet
Dim firstResult As Range
Dim secondResult As Range
Dim rng As Range
Dim LeftCell As Range
Dim leftValue As String
Dim RowCount As Integer
Dim rw As Long
sheetNumber = ActiveWorkbook.Sheets.Count
For counter = 1 To sheetNumber
Sheets(counter).Activate
Set rng = Cells.Find(What:="First Prior Year QRE", after:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True, SearchFormat:=False)
If Not rng Is Nothing Then
Exit For
Else
End If
Next counter
Set LeftCell = rng.Offset(0, -1)
leftValue = LeftCell.Value
If leftValue = "Ref." Then
For rw = 1 To 3
Set findValue = rng.Offset(rw, 0)
datatoFind = findValue
sheetCount = ActiveWorkbook.Sheets.Count
If Len(datatoFind) = 0 Or Not IsNumeric(datatoFind) Then Exit Sub
For counter = 1 To sheetCount
Sheets(counter).Activate
Set firstResult = Cells.Find(What:=datatoFind, after:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
Set secondResult = Cells.FindNext(firstResult)
If Not firstResult Is Nothing Then
MySheet = IIf(InStr(secondResult.Parent.Name, "."), Split(secondResult.Parent.Name, ".")(0), Split(secondResult.Parent.Name)(0))
FV = MySheet & "." & pageNum(secondResult)
Else
End If
Next counter
With rng.Offset(rw, -1)
.Value = FV
.Font.Name = "Times New Roman"
.Font.Bold = True
.Font.Size = "10"
.Font.Color = vbRed
.HorizontalAlignment = xlRight
.VerticalAlignment = xlCenter
End With
Next rw
End If
End Sub
I am working to transition the code to another file, but I cannot send over the file. I am getting a Invalid procedure call or argument on the line for 'set second result'. I assume this has something to do with it not finding the first result, but dont know why that would be. Could it be because I have two "counter" statements? any suggestions?