View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_2_] Don Guillett[_2_] is offline
external usenet poster
 
Posts: 1,522
Default A generic "find" function

Try this function in a REGULAR module using the formula
=fmv("a","p","f")
where a is the string
p is the column and f is for first or l for last


Option Explicit
Function fmv(mv As String, mc As String, fl As String)
Dim mcl As Long
mcl = Cells(1, mc).Column
If UCase(fl) = "F" Then
fmv = Columns(mcl).Find(What:=mv, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Address
Else
fmv = Columns(mcl).Find(What:=mv, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _
MatchCase:=False).Address
End If
End Function

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"xp" wrote in message
...
Using XL2007.

I need a reusable "generic" function that I can call and feed it three
variables:

1) a string to find
2) the column to find it in
3) whether to return the cell address of the first occurrence (top) or
last
(bottom)

Can someone please help me out with this?

Thanks!