Make InStr not case sensitive

gripper

Board Regular
Joined
Oct 29, 2002
Messages
176
Hi folks and Merry Christmas

I was hoping somebody could help me rewrite a code that is not acting like I hoped it should. I believe the code is case sensitive when I would like it not to be. This needs to be flexible because data I am screening can be inconsistent

The line of code is the "If" statement line

Thank you

VBA Code:
' Loop through each cell in the range
    For i = lastColumn To 1 Step -1
        ' Check if the cell value contains "Up" or "Down" (regardless of case)
        If InStr(1, Cells(1, i).Value, "UP") > 0 Or InStr(1, Cells(1, i).Value, "DOWN") > 0 Then
         ' If it does, hide the column
         Columns(i).EntireColumn.Hidden = True
        End If
    Next i
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Please disregard I figured it out. The correct code for reference is

VBA Code:
If UCase(Cells(1, i).Value) = "UP" Or UCase(Cells(1, i).Value) = "DOWN" Then
 
Upvote 0
try ths:
VBA Code:
     If InStr(1, UCase(Cells(1, i).Value), "UP") > 0 Or InStr(1, UCase(Cells(1, i).Value), "DOWN") > 0 Then
 
Upvote 0
FYI Instr has an optional 4th argument for this. Use vbtextcompare for case insensitive
 
Upvote 0

Forum statistics

Threads
1,216,151
Messages
6,129,162
Members
449,489
Latest member
spvclub

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