VBA For "Not Like"

moonbase

New Member
Joined
Nov 6, 2008
Messages
31
Hi,

Could anone please help me with the VBA code for a "Not Like" comparison ?

I get an error when I try to use the "Not Like" comparison

Code:
 If Range("A" & i).Value Not Like "CLOS*" Then


If I use <> "CLOSED" And <> "CLOSE" And <> "CLOSING" then it all runs OK, however I would prefer to get something similar to a "Not Like" operator to work with a wildcard such as *

Thx & Rgds
moonos
 

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 Not (Range("A" & I).Value Like "CLOS*") Then
 
Upvote 0
Peter

They probably aren't needed in this case - I think using that kind of syntax dates back for me to when I studied Logic at university.

I also think it's a good idea to use parentheses to make sure that what your testing is what you want to test.

Then you've also got to consider operator precedence in calculations.

Again I don't know if that would make any difference here but you never know.:)

I mean Man Utd beat Man City in injury time and Celtic beat Hearts too.:)
 
Upvote 0
Thank you for the replies, code now OK.


Peter

I mean Man Utd beat Man City in injury time.:)

The Man Utd win was achieved with referee precedence over a chronological constant. Quite what it has to do with "Not Like" is a bit unclear unless you are a Man City supporter and then it is definitely "Not Liked"


Rgds
moonos
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

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