CountIf function

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
 
C

Chris Lavender

Hi Kittie (Lolly)
This runs fine on my PC, both for XL97 and XL2000. I can generate other
errors by changing the Data range and changing the value types, but not
'subscript out of Range'...
What happens when you step through the code? What line does it stall on?
Best rgds
Chris
 
L

Lolly

Hi
Chris
The problem is it's not giving me any output result .

If you help me out with that

thanx
 
T

Tom Ogilvy

if
rFoundIt.Offset(0, 3)

is empty for Offset(0,-1) = 35 , then your code will show nothing. If not,
it appears to work.
 
T

Tom Ogilvy

Best I can do is test it and it worked for me. Maybe change xlWhole to
xlPart - you might have added spaces.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top