validating string

small

New Member
Joined
May 25, 2004
Messages
26
I have a cell with a value of example ....A46734
ie first postion is a Charcter and next there are 5 numericals
ie need to validate all values for this cells to fit above pattern and then do something if they do else reject if dont .
how is this easily done in VBA.
does any one know of a function.
i need to know how to check for this pattern and return true or false if doesnt fit pattern
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You can use the VBA Like Operator to test for a pattern. Here is a UDF:

Code:
Function IsLike(Txt As String, Pattern As String) As Boolean
    If Txt Like Pattern Then IsLike = True Else IsLike = False
End Function

Your pattern would be "[A-Z]#####". You could use the function in a cell like this:

=IsLike(A1,"[A-Z]#####")

or you could use a cell containing the pattern (no quotes) like this:

=IsLike(A1,$B$1)

where B1 contains the pattern.
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,308
Members
448,886
Latest member
GBCTeacher

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