Option Explicit
Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim myItem As String
Dim FoundCell As Range
Dim myYear As Long
Dim yCtr As Long
Dim HowManyYearsToCheck As Long
Set TrkBk = _
Workbooks.Open("G:\New Items\Tracking Lists\New Item Tracking Log.xls")
myItem = "qwer"
HowManyYearsToCheck = 2
For yCtr = (Year(Date) - 1) To (Year(Date) - 1 + HowManyYearsToCheck - 1)
Set Sht = Nothing
On Error Resume Next
Set Sht = TrkBk.Worksheets(CStr(yCtr))
On Error GoTo 0
If Sht Is Nothing Then
'worksheet doesn't exist, do nothing
Else
With Sht.Range("c4:c3000")
Set FoundCell = .Cells.Find(what:=myItem, _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
'keep looking
Else
Exit For
End If
End With
End If
Next yCtr
If FoundCell Is Nothing Then
MsgBox myItem & " wasn't found"
Else
MsgBox Sht.Name & vbLf _
& FoundCell.Parent.Name & vbLf _
& FoundCell.Address(0, 0)
End If
'I'm not sure what this is supposed to do.
'ActiveSheet.Shapes("button 88").Visible = True
End Sub