Find a string

F

Francis Hookham

I am trying to find the row in which a string occurs but I just do not
understand how.
Can you complete this for me?

Sub zTest()

sDName = "D01-007"

iDRow = .Find(sDName, LookIn:=Range(Cells(6, 2), Cells(30, 2)))

End Sub

Francis Hookham
 
D

Don Guillett

Perhaps a look in the vba help index for FIND would have been of assistance.
This finds if that is the only thing in the cell ( you did not specify)
Sub zTest()

sdname = "D01-007"

'iDRow = .Find(sDName, LookIn:=Range(Cells(6, 2), Cells(30, 2))).Row

x = Range(Cells(6, 2), Cells(30, 2)).Find(sdname).Row
MsgBox x
End Sub
 
G

Guest

Sub zTest()
Dim sDname as String, r as Range, r1 as Range
sDName = "D01-007"
set r = Range(Cells(6, 2), Cells(30, 2))
set r1 =r.Find(sDName)
if not r1 is nothing then
msgbox r1.address
else
msgbox "Not found"
End if




End Sub


Regards,
Tom Ogilvy
 
F

Francis Hookham

Many thanks Tom - I am most grateful.

I'll try both your and Don's answer - yours prompts me to error check which
I shall do.

Francis
 
F

Francis Hookham

Many thanks Don - I did look in Find but wasn't bright enough to realise I
should put .Row at the end.

How you MVPs put up with people like me I do not know - it is a fantastic
service - perhaps in my small way I do the same thing at a much lower level
when my club members ask me such things as why do they keep loosing
everything when, in Word, they type a uppercase A (they press CTRL instead
of shift and then over type everything!

Thanks

Francis
 

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