Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Searching using part of a word rather than whole word in vba


Ok i couldn't think how to word that in to a question very well (it
early and i need a smoke)..
Say i column 1 has several names, i wanna find the name of someon
called.. erm i dunno.. 'Dave'.. my search feature i have present mean
i have to type 'Dave' to find 'Dave', but what about 'David'? I jus
wanna beable to type 'Dav' and find all the 'daves' and 'davids'.
tryed recording a macro of myself doing the good ol' excel searc
(ctrl+f). Now that worked a charm.. except when it doesn't fin
anything and i get the error "Object variable or with block variabl
not set"
Could anyone help meh?

"My current search 'feature'" Wrote:
Private Sub CommandButton1_Click()
Dim search as String
search = txtsearch.Text
Columns("A:A").Select
Selection.fIND(What:=search, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext
_
MatchCase:=False, SearchFormat:=False).Activate
End Su


--
Devit
-----------------------------------------------------------------------
Devitt's Profile: http://www.excelforum.com/member.php...fo&userid=1442
View this thread: http://www.excelforum.com/showthread.php?threadid=26840

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Searching using part of a word rather than whole word in vba

Hi Devitt,

Try something like:

Private Sub CommandButton1_Click()
Dim sh As Worksheet
Dim foundCell As Range
Dim SrchRng As Range
Dim foundCellAdd As String
Dim sStr As String

sStr = txtsearch.Text
Set sh = Me.Parent.Worksheets("sheet1")
Set SrchRng = sh.Range("A:A")

With SrchRng
Set foundCell = .Find(What:=sStr, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
Lookat:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If foundCell Is Nothing Then
'String not found on the sheet so inform user
MsgBox """" & sStr & """" & " not found in " & _
SrchRng.Address & " on " & sh.Name
Else
'String found so take some suitable action, e.g.
foundCellAdd = foundCell.Address
'Return the address of the found string
MsgBox foundCellAdd
'If you must, select the found string
sh.Activate
foundCell.Select
End If
End With

End Sub

---
Regards,
Norman



"Devitt" wrote in message
...

Ok i couldn't think how to word that in to a question very well (its
early and i need a smoke)..
Say i column 1 has several names, i wanna find the name of someone
called.. erm i dunno.. 'Dave'.. my search feature i have present means
i have to type 'Dave' to find 'Dave', but what about 'David'? I just
wanna beable to type 'Dav' and find all the 'daves' and 'davids'. I
tryed recording a macro of myself doing the good ol' excel search
(ctrl+f). Now that worked a charm.. except when it doesn't find
anything and i get the error "Object variable or with block variable
not set"
Could anyone help meh?

"My current search 'feature'" Wrote:
Private Sub CommandButton1_Click()
Dim search as String
search = txtsearch.Text
Columns("A:A").Select
Selection.fIND(What:=search, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
_
MatchCase:=False, SearchFormat:=False).Activate
End Sub



--
Devitt
------------------------------------------------------------------------
Devitt's Profile:
http://www.excelforum.com/member.php...o&userid=14423
View this thread: http://www.excelforum.com/showthread...hreadid=268403



Reply
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
searching for a word(s) within a list Philippa Excel Discussion (Misc queries) 5 August 12th 08 07:30 PM
highlight the word when excel finds text you are searching for Sally M Excel Worksheet Functions 7 September 21st 06 06:07 PM
Is Excel or Word better for holding and searching data Ione Excel Discussion (Misc queries) 2 January 6th 06 09:46 AM
searching a cell for a contained text word Doug K Charts and Charting in Excel 0 June 20th 05 09:10 PM
Vlookup for part of a word jenhow Excel Worksheet Functions 7 April 29th 05 10:22 PM


All times are GMT +1. The time now is 05:37 PM.

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

About Us

"It's about Microsoft Excel"