VBA to Check for a set of Characters in a Variable name

FuzzyTom

New Member
Joined
May 26, 2011
Messages
24
Hi,

I tried to use this code in VBA

if ClName.Formula = Evaluate("=if(iserror(find("ccs",ClName)),0,1) "=" 1 then

I know it is not correct, but here is what I am hoping to achieve.

I would like to check the variable ClName to see if it has an extension of "ccs". For example the clients name, ClName, might be Dennis Morley which is a general client but then I might have a Brian Shaw-ccs and my VBA code above was my attempt to see if I could identity this client in a list of clients. As I loop thru these clients I will me naming the Tabs after each client and and giving each tab a distinctive color ... the clients with the "ccs" extension will have a different tab color than the general clients.

Any help, direction, pointers and tips would be appreciated.

Thanks.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Okay ... ClName is a string so I cannot use it as I have shown.

So I revise my question and ask instead is there a way for me to use evaluate on the Variable ClName such that it would correctly identify the case where I have a ClName with an extension -ccs?

I also revised the Evaluate statement somewhat ... it is now:

= Evaluate("=if(if(iserror(find(""ccs"",ClName)),0,1)" = " 1)") then ... the rest I can take care of once I can get this to work.

Thanks.
 
Upvote 0
Hi Stridhan,

I have ClName defined as a string in a range called ClientWorkName so my code is:

For each l in range(ClientWorkName)
ClName = l.value
TabName = ClName

So later on in the code when I test to see if ClName has a "ccs" extension it still sees ClName as part of the range I think because when I run this:

if instr(1, Clname, "css") <> 0 then

I get this flag "Subscript out of range"

Any thoughts?

Thanks.
 
Last edited:
Upvote 0
thanks for the feedback, great suggestion from mikeerickson!

We learn alot from this page, each and every day :p
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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