Like Operator Help

daily106

Board Regular
Joined
Dec 20, 2004
Messages
158
Can anyone help me with this code?
I am trying to do...

If a cell contains like "Special Word" , then do ABC...
Thank you.

While Rng <> ""

If Rng.Offset(-11, 0).Value = "Special Word" Then
Rng.Value = Rng.Offset(1, 0).Value & " Special Word"
Else
Rng.Value = Rng.Offset(1, 0).Value
End If
Set Rng = Rng.Offset(1)

Wend
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Code:
If LCase$(rng.Value) Like "*myword*" Then
    'Do Something
End If

Although if you are just making a simple check for a Substring inside a string there is a trick you can do with InStr(). InStr is supposed to return the number it found the substring in. So for example InStr("abcde","cd") would return 3. If you happen to know that any non-zero number converts to true, and a zero converts to false. And then top that off with the knowledge that the ByteVersion is faster... Then you can do this:
Code:
If InstrB(LCase$(rng.Value),"myword") Then 
    'Do Something
End If

Why would you do this? Well across a 20 or 30K cells you might notice a small speed improvement. Not really a have to just a nice to know.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

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