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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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