LIKE function in VBA not working

megahurtz

New Member
Joined
Aug 16, 2011
Messages
17
Hi All,

I'm facing a problem in executing the following code snippet :

Code:
sub strtest()

X = [FACT*]*[!FACT*DM]
tbl_nm = "FACT_TSS_PRDCT_ATTRBTS_ABC"
If tbl_nm Like X Then MsgBox "TRUE"

End Sub

This means that if tbl_nm (Table Name) starts with FACT but does not end with DM, the MSGBOX should pop up (condition be satisfied).

But somehow it's not working. Can someone help me please??
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I think you mean:
Code:
x = "FACT*[!DM]"
 
Upvote 0
That Worked!!! Thanks a lot!! :cool:

Can someone please help how to compare a string against a list of substrings??

Eg. If a string FACT_CONTROL_ABC is to be compared against FACT*, DIM*, STG* and a match is found against any of them, the condition should be true.
I tried the following code, but all in vain...

Code:
sub test()
       tbl_nm = "FACT_CONTROL_ABC"
       if tbl_nm like "[FACT*, DIM*, STG*] then MsgBox "TRUE"
end sub
Please help me...
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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