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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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,215,694
Messages
6,126,250
Members
449,305
Latest member
Dalyb2

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