Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default cell validation/format masks???

Hi Everybody

I have a list of cells with alphanumeric data in it eg ("01R1234567")
I want to write an if statement to check that the contents of the cells is a
valid reference.

Is there any way to check the individual characters for there values
eg IF A1 = "NNANNNNNNN" Then B1 = "valid" (N=numberic A=Aplph)
else B1 = "corrupt"
End If

Thanks
Anthony
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default cell validation/format masks???

Hi Anthony,
I don't think there is any direct way. However you can use the worksheet
function bellow (HasPattern(,)) which uses the LIKE operator (see vba online
help)
'-------------------------------------------------------------------------------
'HasPattern returns the value of the expression: Str LIKE Pattern
'It returns #Value error if either STr or Pattern cannot be converted into
strings.
Public Function HasPattern(Str As Variant, Pattern As String) As Variant
Dim s1 As String, s2 As String

On Error Resume Next
s1 = CStr(Str)
s2 = CStr(Pattern)
If Err < 0 Then 'if error, returns #Value
HasPattern = CVErr(xlErrValue)
Else
HasPattern = (Str Like Pattern)
End If
End Function
'-----------------------------------------------------------------

In the sheet, in your case, in B1, enter:
=HasPattern(UPPER(A1),"##[A-Z]#######")
will retun True if A1 is like "NNANNNNNNN"
else False

You can also use it in :
-Conditional Formatting (Format of the cell varies based on a condition:
menu Format Conditional Formatting) or
- Dat Validation: validates user data entry (menu Data Validation)
- directly within vba

I hope this helps,
Sebastien

"antinoz" wrote:

Hi Everybody

I have a list of cells with alphanumeric data in it eg ("01R1234567")
I want to write an if statement to check that the contents of the cells is a
valid reference.

Is there any way to check the individual characters for there values
eg IF A1 = "NNANNNNNNN" Then B1 = "valid" (N=numberic A=Aplph)
else B1 = "corrupt"
End If

Thanks
Anthony

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 280
Default cell validation/format masks???

Didn't you see the several fine responses to your post of 9/8/2004 9:53 PM
??

"antinoz" wrote in message
...
Hi Everybody

I have a list of cells with alphanumeric data in it eg ("01R1234567")
I want to write an if statement to check that the contents of the cells is

a
valid reference.

Is there any way to check the individual characters for there values
eg IF A1 = "NNANNNNNNN" Then B1 = "valid" (N=numberic A=Aplph)
else B1 = "corrupt"
End If

Thanks
Anthony



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default cell validation/format masks???

A big thank you to all the guys who responded to the previous "duplication".
I foolishly lost the question and could not find it again so thinking I had
not infact posted one I did it again. apologies and thanks

thanks also sebastienm for responding along with, Bob, Don & Dave

cheers guys

"Bob Kilmer" wrote:

Didn't you see the several fine responses to your post of 9/8/2004 9:53 PM
??

"antinoz" wrote in message
...
Hi Everybody

I have a list of cells with alphanumeric data in it eg ("01R1234567")
I want to write an if statement to check that the contents of the cells is

a
valid reference.

Is there any way to check the individual characters for there values
eg IF A1 = "NNANNNNNNN" Then B1 = "valid" (N=numberic A=Aplph)
else B1 = "corrupt"
End If

Thanks
Anthony




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format Cell and Data Validation Maki Excel Discussion (Misc queries) 4 September 1st 08 07:19 AM
Cell validation = format? John Excel Discussion (Misc queries) 2 March 22nd 08 10:22 PM
input masks and validation archiboy Excel Discussion (Misc queries) 3 October 11th 05 03:05 PM
Boolean masks Howard Excel Worksheet Functions 2 April 3rd 05 08:22 PM
Lists and masks Colin[_5_] Excel Programming 1 July 15th 03 01:38 AM


All times are GMT +1. The time now is 08:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"