Change Instr to exact whole word match

cortexnotion

Board Regular
Joined
Jan 22, 2020
Messages
150
Office Version
  1. 2013
Platform
  1. Windows
Hi All

I have the below code, but I have found Instr is picking up partial matches inside words, when I need it to match to whole words only inside the string. Could anyone suggest how to achieve this please?

Thanks :)

VBA Code:
For i = LBound(ArrIN) To UBound(ArrIN)
                                    
        If InStr(ArrIN(i, 2), "CO ") = 0 And InStr(ArrIN(i, 2), "CU ") = 0 And InStr(ArrIN(i, 2), "CDIWE") = 0 And InStr(ArrIN(i, 8), "Water") > 0 And _
        ArrIN(i, 9) > 0 And ArrIN(i, 16) > 0 Then
        
        For b = LBound(BucketArray) To UBound(BucketArray)
            If InStr(ArrIN(i, 2), BucketArray(b)) > 0 Then GoTo NR1
        Next b
                                    
        For m = LBound(MatchArray) To UBound(MatchArray)
            If InStr(ArrIN(i, 3) & ArrIN(i, 4), MatchArray(m)) > 0 Then GoTo NR1
        Next m
        
        For x = 0 To UBound(ColAry)
            ArrOUT(o, x + 1) = ArrIN(i, ColAry(x))
        Next x
        o = o + 1
    End If
NR1:     Next i
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Probably this approach will do the job:
Rich (BB code):
If InStr(ArrIN(i, 2) & " ", BucketArray(b) & " ") > 0 Then GoTo NR1

The modifications are in Blue

Bye
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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