1.

Solve : VBA IF statement not case sensitive?

Answer» HI GUYS,

I'm a beginner in VBA and I need your knowledge to help me with this code.
i want to PUT it as case UNsensitive.
can you type me the right code, please?



Sub rename_raw()

Dim i As Long

For i = 2 To 70000
    If Cells(i, 3).Value = "Raw-material feed" Then
        If InStr(Cells(i, 1), "A") > 0 Or InStr(Cells(i, 1), "B") > 0 Then
            Cells(i, 9).Value = "AB"
         End If
    End If
Next i

End Sub


thank you!! Quote
Code: [Select]For i = 2 To 70000
    If Cells(i, 3).Value = "Raw-material feed" Then
        If InStr(Cells(i, 1), "A") > 0 Or InStr(Cells(i, 1), "B") > 0 Then
            Cells(i, 9).Value = "AB"
         End If
    End If
Next i

2 ways that should work:

Code: [Select]For i = 2 To 70000
    If Cells(i, 3).Value = "Raw-material feed" Then
        If InStr(Cells(i, 1), "A") > 0 Or or InStr(Cells(i, 1), "a") > 0 InStr(Cells(i, 1), "B") > 0 Or or InStr(Cells(i, 1), "b") > 0 Then
            Cells(i, 9).Value = "AB"
         End If
    End If
Next i

Code: [Select]For i = 2 To 70000
    If Cells(i, 3).Value = "Raw-material feed" Then
        If InStr(UCASE(Cells(i, 1)), "A") > 0 Or InStr(UCASE(Cells(i, 1)), "B") > 0 Then
            Cells(i, 9).Value = "AB"
         End If
    End If
Next i
InStr also supports a comparison argument, though you have to also provide the optional starting position argument if it is specified, so it doesn't end up any SHORTER than forcing case before the COMPARE.

Code: [Select]For i = 2 To 70000
    If Cells(i, 3).Value = "Raw-material feed" Then
        If InStr(1,Cells(i, 1), "A", vbTextCompare) > 0 Or InStr(1, Cells(i, 1), "B", vbTextCompare) > 0 Then
            Cells(i, 9).Value = "AB"
         End If
    End If
Next i


Discussion

No Comment Found