Search String not ignoring CAPS

tony.reynolds

Board Regular
Joined
Jul 8, 2010
Messages
97
how can i make the following code return results for words in UPPERCASE the same as lowercase

At the moment if the string includes the word Test it finds "Test" but not "test" for instance or
it finds "Test" not "TEST"

Code:
Private Sub TextBoxSearchItemList_Change()
Application.ScreenUpdating = False
Range("FilteredPartsList").ClearContents
Dim FilteredListTopLeftCorner As Range
Dim FilteredListBottomLeftCorner As Range
Dim CurrentSearchCell As Range
Dim CurrentFilteredListCell As Range
Dim Check1 As Boolean
Dim SearchString1
Dim SearchString2
If TextBoxSearchItemList = Empty Or TextBoxSearchItemList Like "?" Or _
TextBoxSearchItemList Like "??" Or _
TextBoxSearchItemList Like "???" Or _
TextBoxSearchItemList Like "????" _
Then
NewPartDescriptionChart.RowSource = "AllPartsViewColumns"
Exit Sub
End If
Set FilteredListTopLeftCorner = Range("FilteredItemsStart")
'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
SearchString1 = CurrentSearchCell.Text & " " & CurrentSearchCell.Offset(0, 1).Text
Check1 = SearchString1 Like SearchString2
If Check1 = True Then
CurrentFilteredListCell = CurrentSearchCell
CurrentFilteredListCell.Offset(0, 1) = CurrentSearchCell.Offset(0, 1)
CurrentFilteredListCell.Offset(0, 2) = Format(CurrentSearchCell.Offset(0, 2), "$#,##0.00")
CurrentFilteredListCell.Offset(0, 3) = CurrentSearchCell.Offset(0, 3)
CurrentFilteredListCell.Offset(0, 4) = CurrentSearchCell.Offset(0, 4)
CurrentFilteredListCell.Offset(0, 5) = CurrentSearchCell.Offset(0, 5)
CurrentFilteredListCell.Offset(0, 6) = CurrentSearchCell.Offset(0, 6)
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
Set FilteredListBottomLeftCorner = CurrentFilteredListCell.Offset(0, 6)
ActiveWorkbook.Names.Add Name:="FilteredPartsList", RefersTo:=Range(FilteredListTopLeftCorner, FilteredListBottomLeftCorner)
NewPartDescriptionChart.RowSource = "FilteredPartsList"

End Sub

Any ideas would be great
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Based on this you wrote:

At the moment if the string includes the word Test it finds "Test" but not "test" for instance or
it finds "Test" not "TEST"

It sounds like, contrary to your subject line "not ignoring CAPS" that you *do* want to ignore CAPS and accept any upper or lower case combination.

One way to accomplish this is to place the following statement at the top of your module:

Option Compare Text

Note, "at the top of your module" means just that -- above and outside of all macros UDFs, and procedures.
 
Upvote 0
Actually i worked it out.

i chanced the strings to this...

SearchString1 = StrConv(CurrentSearchCell & " " & CurrentSearchCell.Offset(1, 0).Text, vbLowerCase)
SearchString2 = StrConv("*" & TextBoxSearchItemList & "*", vbLowerCase)

Fixes it.

Thanks anyway ill try your suggestion too.
 
Upvote 0
One way to accomplish this is to place the following statement at the top of your module:

Option Compare Text
QUOTE]

Yes thats much better.

I found that the way i tried to do it with
Code:
StrConv("*" & TextBoxSearchItemList & "*", vbLowerCase)

dosnt work if the string starts with a number eg "12 Volt Power" will not convert to "12 volt power"

Thanks a stack tom
 
Upvote 0

Forum statistics

Threads
1,215,832
Messages
6,127,152
Members
449,366
Latest member
reidel

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