Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default ID Validation using macros in excel

Hi All,

I need help in creating a macro which can validate IDs listed in a
column in spread sheet.

There is a fixed format for each ID:

The first 5 places of the ID should be characters.
The next 4 should be numericals
Last 1 should be a character
4th character from beginning should be "P"

Examples of some of the IDs:

ACCPR4243A
BDKPZ6145M
LNHPC3807D

thank you all in advance.

Sri...

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 233
Default ID Validation using macros in excel

Design a formula in XL that evaluates to TRUE/FALSE for
correct/incorrect ID's

Use Data-validation and use option Formula. and use the created
formula to evaluate ID's on cell data entry.

Dm Unseen

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default ID Validation using macros in excel

The function you;re looking for is TypeName.

So something like this might just work.

-----------------------------------------------

Sub YourSubName()

Dim strCellValue As String

strCellValue = Range("A1").Text

If TypeName(Left(strCellValue, 5)) = "String" And TypeName(Mid(strCellValue,
6, 4)) = "Double" _
And TypeName(Right(strCellValue, 1)) = "String" And Mid(strCellValue, 4,
1) = "p" Then
Do Something
Else
MsgBox "Not correct format"
End If

End Sub

------------------------------------------------------------

Not sure if you want to loop through all of them in one hit or what you want
to do if it's wrong, but this should be a good starter for 10 I hope.

HTH.

"Sridhar Machina" wrote:

Hi All,

I need help in creating a macro which can validate IDs listed in a
column in spread sheet.

There is a fixed format for each ID:

The first 5 places of the ID should be characters.
The next 4 should be numericals
Last 1 should be a character
4th character from beginning should be "P"

Examples of some of the IDs:

ACCPR4243A
BDKPZ6145M
LNHPC3807D

thank you all in advance.

Sri...


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default ID Validation using macros in excel

Hi, Sridhar,

I couldn't get DaveO's solution to work, so i came up with this:

Sub ValidateString()

'Characters 1-5 are non-numeric
'Character 5 = "P"
'Characters 6-9 are numbers
'Last Character is non-numeric

Dim StrCellValue As String
Dim TestCell As Range

For Each TestCell In Selection

StrCellValue = TestCell.Text

If Not (IsNumeric(Left(StrCellValue, 5))) _
And Mid(StrCellValue, 4, 1) = "P" _
And IsNumeric(Mid(StrCellValue, 6, 4)) _
And Not (IsNumeric(Right(StrCellValue, 1))) Then
MsgBox ("Value in row " & TestCell.Row & " - Format
OK")
Else
MsgBox ("Value in row " & TestCell.Row & " - Format Incorrect")
End If
Next

End Sub

The macro works for a range of cells, as against just one - highlight all
the cells you want to test before you run this macro - it should be OK

Regards

Pete



"Sridhar Machina" wrote:

Hi All,

I need help in creating a macro which can validate IDs listed in a
column in spread sheet.

There is a fixed format for each ID:

The first 5 places of the ID should be characters.
The next 4 should be numericals
Last 1 should be a character
4th character from beginning should be "P"

Examples of some of the IDs:

ACCPR4243A
BDKPZ6145M
LNHPC3807D

thank you all in advance.

Sri...


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default ID Validation using macros in excel

Thank you, peter, its working for me.

Thanks again

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
Excel 2007-programming macros that apply to data validation Derek Megyesi New Users to Excel 1 January 31st 10 10:11 PM
Macros & Validation John Calder New Users to Excel 0 June 13th 06 02:48 AM
Validation/Macros Tom Ogilvy Excel Programming 1 January 15th 04 04:21 PM
Validation/Macros Ron de Bruin Excel Programming 1 January 15th 04 04:19 PM
Validation/Macros Ron de Bruin Excel Programming 0 January 15th 04 04:13 PM


All times are GMT +1. The time now is 02:30 AM.

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"