Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default searching for words

morning all,

I have a sub that searches a list box of values for matching words from a
text box. The problem is I only want to find whole words and it will
currently return results if the letters are part of a word (ie searching for
low will return airflow) and I cannot seam to fix the problem. Below is the
sub.

Public Sub PopulateList()

Dim myCell As Range
Dim myRng As Range
Dim FoundCell As Range
Dim FoundRng As Range
Dim FirstAddress As String


With Worksheets([mySheet])

MainTagForm!ColumnListBox.Clear

Set myRng = .Range([myColumn] & "2", .Cells(.Rows.Count,
[myColumn]).End(xlUp))
End With

If MainTagForm!SearchTextBox = "" Then
For Each myCell In myRng.Cells
If myCell.Value < 0 Then
MainTagForm!ColumnListBox.AddItem myCell.Value
End If
Next myCell
End If

If MainTagForm!SearchTextBox < "" Then
' 'finds first value
For Each myCell In myRng.Cells
If myCell.Value =
Cells.Find(what:=MainTagForm!SearchTextBox.Value, LookIn:=xlFormulas,
lookat:=xlPart, MatchCase:=False) Then
MainTagForm!ColumnListBox.AddItem myCell.Value
FirstAddress = myCell.Address
Set FoundCell = myCell
End If
Next myCell

With myRng

Set myCell = FoundCell
Set FoundRng = Nothing


Do
' finds the rest of the values
If FoundRng Is Nothing Then
Set FoundRng = myCell
Else
Set FoundRng = Union(FoundRng, myCell)
End If

Set myCell = .FindNext(after:=myCell)
MainTagForm!ColumnListBox.AddItem myCell.Value
If myCell.Address = FirstAddress Then Exit Do
Loop
End With
End If

'MsgBox [mySheet]
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default searching for words

Hi Jim,

have you tried:

LookAt:=xlWhole

Helmut Weber
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default searching for words

I keep getting a run time error 9, object variable or with block variable
not set.


"Helmut Weber" wrote:

Hi Jim,

have you tried:

LookAt:=xlWhole

Helmut Weber

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 Text that contains particular WORDS. Abdullah Kajee Excel Worksheet Functions 9 August 27th 07 07:52 AM
Searching for multiple words in a cell JJ[_3_] Excel Programming 1 April 17th 07 10:00 AM
Searching for words used in VBA code Morten Hvidberg-Knudsen[_2_] Excel Programming 5 February 22nd 07 09:58 PM
Searching for the presence of specific words Ryan Ferrell Excel Worksheet Functions 1 December 25th 05 10:34 PM
Searching for a words in a column from a list of words. Scott Excel Programming 5 August 15th 03 02:40 PM


All times are GMT +1. The time now is 06:47 AM.

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"