Search entire row for string

tony.reynolds

Board Regular
Joined
Jul 8, 2010
Messages
97
I'm wanting to search two columns for the string in TextBoxSearchItemList.text. then put these values into another list position.

as you can see here ive made a raw idea of what im trying to do but i think im trying the wrong method.

any help would be appreciated.

Ive tried to search for the TextBoxSearchItemList.text anywhere in the string using * each end but i dont know how to use it to well.



Code:
Private Sub TextBoxSearchItemList_Change()
Dim CurrentSearchCell As Range
Dim CurrentFilteredListCell As Range
Dim Check1 As Boolean

'Filter available Parts
Set CurrentSearchCell = Range("PartDescriptions").Offset(1, 0)
Set CurrentFilteredListCell = Range("FilteredItemsStart")
SearchString1 = CurrentSearchCell.Text & " " & CurrentSearchCell.Offset(1, 0).Text
SearchString2 = TextBoxSearchItemList
Do
Check1 = SearchString1 Like "*" & SearchString2 & "*"
If Check1 = True And Not TextBoxSearchItemList = Empty Then
CurrentFilteredListCell = CurrentSearchCell
CurrentFilteredListCell.Offset(0, 1) = CurrentSearchCell.Offset(0, 1)
Set CurrentFilteredListCell = CurrentFilteredListCell.Offset(1, 0)
Set CurrentSearchCell = CurrentSearchCell.Offset(1, 0)
Else
Set CurrentSearchCell = CurrentSearchCell.Offset(1, 0)
End If
Loop Until CurrentSearchCell = Empty

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Sorry Code i intended to post was

Code:
Private Sub TextBoxSearchItemList_Change()
Dim CurrentSearchCell As Range
Dim CurrentFilteredListCell As Range
Dim Check1 As Boolean
Dim SearchString1 As String
Dim SearchString2 As String
 
If TextBoxSearchItemList = Empty Then Exit Sub
'Filter available Parts
Set CurrentSearchCell = Range("PartDescriptions").Offset(1, 0)
Set CurrentFilteredListCell = Range("FilteredItemsStart")
SearchString1 = CurrentSearchCell.Text & " " & CurrentSearchCell.Offset(1, 0).Text
SearchString2 = "*" & TextBoxSearchItemList & "*"
Do
Check1 = SearchString1 Like SearchString2
If Check1 = True Then
CurrentFilteredListCell = CurrentSearchCell
CurrentFilteredListCell.Offset(0, 1) = CurrentSearchCell.Offset(0, 1)
Set CurrentFilteredListCell = CurrentFilteredListCell.Offset(1, 0)
Set CurrentSearchCell = CurrentSearchCell.Offset(1, 0)
SearchString1 = CurrentSearchCell.Text & " " & CurrentSearchCell.Offset(1, 0).Text
Else
Set CurrentSearchCell = CurrentSearchCell.Offset(1, 0)
End If
Loop Until CurrentSearchCell = Empty
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top