simple code with "abc" & "*"

J

Jack Sons

Hi al,

I have this line of code:
If Range(Cells(commentrij, 43), Cells(commentrij, 43)).Text = "abc"
& "*" Then

The cell contains abc followed by some other characters (depending on the
row) but this line will not work.
If I use the complete text of the content of the cell, e.g. "abcdef", the
line of code works properly.
I guess "abc" & "*" is incorrect, but I don't know why.
What shoud it be?
Thanks in advance for your help.

Jack Sons
The Netherlands
 
D

Dave Peterson

Wildcards don't work with this simple comparison.

You could use like:
if range(...).text like "abc*" then

or you could check the first 3 characters:
if left(range(...).text, 3) = "abc" then

ps. You don't need that .range(...) stuff--it's a single cell:

if cells(commentrij,43).text like ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top