LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Function to search different worksheet


Hi all,

Just wondering if I've missed something obvious or if this can't be
done.

Basically I'm trying to write a function that will search for similar
names on a different sheet and return a comma separated string of the
matching names. Here's what I've got as a module within the workbook
(by the way this is Excel 2003 SP2 on XP Pro) -

Public Function clients(mystr As String) As String
Dim wksht As Worksheet, c As Range, firstaddress As String

Set wksht = Sheets("Clients")
With wksht.UsedRange
Set c = .Find(What:=mystr, After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:=xlNext, MatchCase:=False)
If Not c Is Nothing Then
firstaddress = c.Address
Do
If Len(clients) = 0 Then
clients = c.Text
Else
If InStr(1, clients, c.Text) = 0 Then
clients = clients & ", " & c.Text
End If
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With

End Function

However this fails on the 4th line set c = .find and gives the classic
type mismatch. What I've found is that it works perfectly if I select
the sheet and then run the function, but obviously when using the
function on a different sheet you can't select the sheet first -
besides it makes the user experience a bit bad.

Any ideas? Either to fix or a new approach to solve the same thing.

Only thing I can think of at the moment is to put the list of clients
on the same worksheet, but this isn't the nice solution I was looking
for.

Thanks in advance,

Brad

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Search Function In Excel Worksheet Dileep Excel Worksheet Functions 0 September 29th 06 09:59 AM
FIND or SEARCH worksheet function Mike Archer Excel Programming 1 February 13th 06 04:31 PM
Create a search Field within a worksheet to search command buttons Ed P[_2_] Excel Programming 1 December 14th 04 08:04 PM
Search for a Specific Worksheet Macro or Function? snsd[_4_] Excel Programming 0 November 2nd 04 05:58 PM
Search for a Specific Worksheet Macro or Function? snsd[_3_] Excel Programming 1 November 2nd 04 04:31 PM


All times are GMT +1. The time now is 06:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"