# Make InStr not case sensitive



## gripper (Dec 24, 2022)

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


```
' 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
```


----------



## gripper (Dec 24, 2022)

Please disregard I figured it out.  The correct code for reference is


```
If UCase(Cells(1, i).Value) = "UP" Or UCase(Cells(1, i).Value) = "DOWN" Then
```


----------



## offthelip (Dec 24, 2022)

try ths:

```
If InStr(1, UCase(Cells(1, i).Value), "UP") > 0 Or InStr(1, UCase(Cells(1, i).Value), "DOWN") > 0 Then
```


----------



## gripper (Dec 24, 2022)

offthelip said:


> try ths:
> 
> ```
> If InStr(1, UCase(Cells(1, i).Value), "UP") > 0 Or InStr(1, UCase(Cells(1, i).Value), "DOWN") > 0 Then
> ```





offthelip said:


> try ths:
> 
> ```
> If InStr(1, UCase(Cells(1, i).Value), "UP") > 0 Or InStr(1, UCase(Cells(1, i).Value), "DOWN") > 0 Then
> ```


Offthelip

I think you solution is best.

Thank you


----------



## RoryA (Dec 24, 2022)

FYI Instr has an optional 4th argument for this. Use vbtextcompare for case insensitive


----------

