Search for partial text from cell value

ilikered100

New Member
Joined
May 29, 2013
Messages
46
Ok... so I have a simple piece of code that works fine.

Basically it is checking the ActiveCell to see if any part of the cell contains the word "Cat" and if it does, it returns "True" in the cell one column to the right.

'Checks the activecell value to see if any part of the cell contains the text "Cat"
If ActiveCell.Value Like "*Cat*" Then
ActiveCell.Offset(0, 1).Value = "True"
End If

What I would like it to do is to check the ActiveCell to see if any part of the cell contains the word "Cat" but I would like to reference a cell that contains the word "Cat" (e.g. cell A1) instead of the actual word "Cat"

I tried something like this, but it didn't work

'Checks the activecell value to see if any part of the cell contains the text in cell A1
If ActiveCell.Value Like "*Cells(1,1)*" Then
ActiveCell.Offset(0, 1).Value = "True"
End If

Any help is appreciated.




 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try this:
Code:
If ActiveCell.Value Like "*" & Cells(1, 1) & "*" Then
    ActiveCell.Offset(0, 1).Value = "True"
End If
 
Upvote 0
You are welcome!

With VBA, the key point to remember that anything found between double-quotes is treated as literal text, so you do not want variables or formulas in between them (unless you are actually trying to put a formula in a cell).
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

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