L
Lolly
When I am writing this code.
Error is subscript out of Range
Code is as Follows
Sub FindBillyBrown35()
Dim vOurResult
Dim rFoundIt As Range
Dim iLoop As Integer
' FindBillyBrow Macro
' Using the Find Method over Vlookup
'
With Sheet1.Range("Data")
'Set variable to start search from
Set rFoundIt = .Cells(1, 1)
'Loop no more times that the name occurs
For iLoop = 1 To WorksheetFunction.CountIf _
(Sheet1.Range("Data"), "Billy Brown")
'ReSet variable to found occurence of name. Next loop search _
will start AFTER this Set cell.
Set rFoundIt = .Find(What:="Billy Brown", After:=rFoundIt, _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
'Check if it's the right one.
If rFoundIt.Offset(0, -1).Value = 35 Then
vOurResult = rFoundIt.Offset(0, 3)
Exit For 'Leave loop
End If
Next iLoop
End With 'Sheet1.Range("Data")
If Not IsEmpty(vOurResult) Then 'Variable holds a value
MsgBox vOurResult
End If
End Sub
Any help would be appreciated
Error is subscript out of Range
Code is as Follows
Sub FindBillyBrown35()
Dim vOurResult
Dim rFoundIt As Range
Dim iLoop As Integer
' FindBillyBrow Macro
' Using the Find Method over Vlookup
'
With Sheet1.Range("Data")
'Set variable to start search from
Set rFoundIt = .Cells(1, 1)
'Loop no more times that the name occurs
For iLoop = 1 To WorksheetFunction.CountIf _
(Sheet1.Range("Data"), "Billy Brown")
'ReSet variable to found occurence of name. Next loop search _
will start AFTER this Set cell.
Set rFoundIt = .Find(What:="Billy Brown", After:=rFoundIt, _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
'Check if it's the right one.
If rFoundIt.Offset(0, -1).Value = 35 Then
vOurResult = rFoundIt.Offset(0, 3)
Exit For 'Leave loop
End If
Next iLoop
End With 'Sheet1.Range("Data")
If Not IsEmpty(vOurResult) Then 'Variable holds a value
MsgBox vOurResult
End If
End Sub
Any help would be appreciated