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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,223,676
Messages
6,173,758
Members
452,534
Latest member
autodiscreet

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