Cell entry limit to 00000 through 99999

Hi all, how to use vba in excel to limit cell entries to numbers from 00000 through 99999?
Thank You,
Steve
steve smithAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlanConsultantCommented:
Hi,

No need to use VBA - you can do it with data validation.

If you want to control if from VBA, the setup the data validation through there.

Hope that helps,

Alan.
0
Ejgil HedegaardCommented:
00000 is not a number, but a text.
To input it, the cell must be formatted as text.
If not, Excel will convert it to the number 0
You could use a custom validation rule like =AND(ISNUMBER(A1*1),LEN(A1)=5)

If you want to use VBA it could be something like this
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Integer, j As Integer
    If Target.Count = 1 Then
        If Len(Target.Value) = 5 Then
            For i = 1 To 5
                If Asc(Mid(Target.Value, i, 1)) >= 48 And Asc(Mid(Target.Value, i, 1)) <= 57 Then
                    j = j + 1
                End If
            Next i
        End If
    End If
    If j <> 5 Then
        MsgBox "Wrong input"
        Application.EnableEvents = False
        Target.ClearContents
        Application.EnableEvents = True
    End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rgonzo1971Commented:
Hi,

pls try

Regards
EE20180127.xlsx
0
steve smithAuthor Commented:
Thank very much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.