Data Validaiton formula containing numbers and text

madams_08

New Member
Joined
Jun 18, 2012
Messages
8
I read a previous article and non of the formulas worked for my worksheet.

I need to validate a cell for the following custom format, but cant get it to work:

1. XX00000
2. 00000000XX
3. 000000X

Where XX is any combination of letters (upper or lowercase) and
00000 is a combination of any 5 numbers.

All of these formaulas can not allow special characters.

It must always be in this format, with this number of digits in total on each
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hello, maybe so:
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim pRg As New VBScript_RegExp_55.RegExp, pM As VBScript_RegExp_55.Match
    Dim pMs As VBScript_RegExp_55.MatchCollection
    If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
        pRg.Global = True: pRg.Pattern = "([A-Za-z]{1,}|)\d{1,}([A-Za-z]{1,}|)"
        Set pMs = pRg.Execute(Target)
        If pMs.Count > 0 Then
        Else
            MsgBox ("Error")
        End If
    End If
End Sub

Before you should set Microsoft VBScript Regular Expressions 5.5
 
Upvote 0
I read a previous article and non of the formulas worked for my worksheet.

I need to validate a cell for the following custom format, but cant get it to work:

1. XX00000
2. 00000000XX
3. 000000X

Where XX is any combination of letters (upper or lowercase) and
00000 is a combination of any 5 numbers.

All of these formaulas can not allow special characters.

It must always be in this format, with this number of digits in total on each
Try these...

For XX00000:

=AND(LEN(A2)=7,ABS(CODE(UPPER(A2))-77.5)<13,ABS(CODE(UPPER(MID(A2,2,1)))-77.5)<13,COUNT(-MID(A2,ROW(INDIRECT("3:7")),1))=5)

For 00000000XX:

=AND(LEN(A2)=10,ABS(CODE(UPPER(MID(A2,9,1)))-77.5)<13,ABS(CODE(UPPER(MID(A2,10,1)))-77.5)<13,COUNT(-MID(A2,ROW(INDIRECT("1:8")),1))=8)

For 000000X:

=AND(LEN(A2)=7,ABS(CODE(UPPER(RIGHT(A2)))-77.5)<13,COUNT(-MID(A2,ROW(INDIRECT("1:6")),1))=6)

If you test those formulas on the worksheet they must be array entered.

Array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
Im excited I have all except 1 of them working.

The one that doesnt work is

For 00000000XX:

=AND(LEN(A2)=10,ABS(CODE(UPPER(MID(A2,9,1)))-77.5)<13,ABS(CODE(UPPER(MID(A2,10,1)))-77.5)<13,COUNT(-MID(A2,ROW(INDIRECT("1:8")),1))=8)

What is wrong with this formula?
 
Upvote 0
Im excited I have all except 1 of them working.

The one that doesnt work is

For 00000000XX:

=AND(LEN(A2)=10,ABS(CODE(UPPER(MID(A2,9,1)))-77.5)<13,ABS(CODE(UPPER(MID(A2,10,1)))-77.5)<13,COUNT(-MID(A2,ROW(INDIRECT("1:8")),1))=8)

What is wrong with this formula?
Works OK for me.

Can you post some samples that causes it to not work as needed?
 
Upvote 0
Nevermind I got the formula to work in a blank spreadsheet. I need to figure out what is wrong with my cell. Thank you sooo much for all of your help!!!
 
Upvote 0

Forum statistics

Threads
1,211,983
Messages
6,105,214
Members
447,956
Latest member
haluxuxjr

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