If Is Equal To

tomgrandy

New Member
Joined
May 10, 2024
Messages
41
Office Version
  1. 365
Platform
  1. MacOS
Currently I have a string as:

If InStr(cell.Value, "DRILL") <> 0 Then
cell.Offset(0, 7).Value = "POINT"
End If

It needs to read that if that cell value equals DRILL then write the value of POINT

Problem that I am encountering is that where the descriptions it is reading for values from has the word "Drilled" as in a tooth that was drilled (not a Point) that is shows another value.

So, how do I rewrite the above to ONLY pick up Drill and not Drilled?

Thanks in advance,

Tom
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I'm thinking this should do it:

If InStr(cell.Value, "DRILL") Then
cell.Offset(0, 7).Value = "POINT"
End If
 
Upvote 0
That didn't work. Need it to be exactly equal to DRILL so as not to grab the value of DRILLED
 
Upvote 0
Maybe
VBA Code:
If InStr(cell.Value, " DRILL ") Then
cell.Offset(0, 7).Value = "POINT"
End If
 
Upvote 0
Solution
You're welcome

Btw you don't need the End If when doing a single test, you can just write it as a single line
VBA Code:
If InStr(cell.Value, " DRILL ") Then cell.Offset(0, 7).Value = "POINT"
 
Upvote 0
You're welcome

Btw you don't need the End If when doing a single test, you can just write it as a single line
VBA Code:
If InStr(cell.Value, " DRILL ") Then cell.Offset(0, 7).Value = "POINT"

What if I am writing line after line like these (literally hundreds). Is there a more efficient way for the macro to run?

Excel Formula:
        If InStr(cell.Value, "PENDANT") > 0 Then
            cell.Offset(0, 8).Value = "PENDANT AND GORGETS"
        End If
        
        If InStr(cell.Value, "GORGET") > 0 Then
            cell.Offset(0, 8).Value = "PENDANT AND GORGETS"
        End If
        
        If InStr(cell.Value, "BANNERSTONE") > 0 Then
            cell.Offset(0, 8).Value = "BANNERSTONES & ATL-ATL WEIGHTS"
        End If
        
       If InStr(cell.Value, "BANNERS") > 0 Then
            cell.Offset(0, 8).Value = "BANNERSTONES & ATL-ATL WEIGHTS"
        End If
        
        If InStr(cell.Value, "LOAFSTONE") > 0 Then
            cell.Offset(0, 8).Value = "BANNERSTONES & ATL-ATL WEIGHTS"
        End If
        
        If InStr(cell.Value, "BAR AMULET") > 0 Then
            cell.Offset(0, 8).Value = "BANNERSTONES & ATL-ATL WEIGHTS"
        End If
 
Upvote 0
Don't know about more efficient but maybe easier to write (Change myCell to suit)

VBA Code:
    Dim MyArr, MyArr2, myCell As Range
    Dim MyFind As Integer, MyFind2 As Integer

    Set myCell = Range("A4")

    MyArr = Array("PENDANT", "GORGET")
    MyArr2 = Array("BANNERSTONE", "BANNERS", "LOAFSTONE", "BAR AMULET")

    For MyFind = LBound(MyArr) To UBound(MyArr)
        If InStr(myCell.Value, " " & MyArr(MyFind) & " ") > 0 Then myCell.Offset(0, 8).Value = "PENDANT AND GORGETS"
    Next
        
    For MyFind2 = LBound(MyArr2) To UBound(MyArr2)
        If InStr(myCell.Value, " " & MyArr2(MyFind2) & " ") > 0 Then myCell.Offset(0, 8).Value = "BANNERSTONES & ATL-ATL WEIGHTS"
    Next
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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