troubleshooting Question

InputBox, restricting special chars?

Avatar of RWayneH
RWayneHFlag for United States of America asked on
VBAMicrosoft ExcelMicrosoft Office
11 Comments1 Solution73 ViewsLast Modified:
Is there a way to restrict special characters, on an inputbox?  I was testing this and my mouse fell on the keyboard, adding a / character, so I went with it and oddly it made the procedure fail.  Either I need to Dim strNewListItemName as something different or add another ElseIf.  Please advise and thanks.  ( way odd to find this failure that way.  lol)

        strNewListItemName = InputBox("Please enter an account name.", "Enter new account name", SampleName)
        If strNewListItemName = "New Account name." Then
            MsgBox ("You need to change the default account input")
        ElseIf StrPtr(strNewListItemName) = 0 Then
            Exit Sub
        ElseIf strNewListItemName = "" Then
            MsgBox ("Can not be blank or use the default input text")
        ElseIf Len(strNewListItemName) > 30 Then
            MSG1 = MsgBox("Your account name exceeded 30 characters, try shortening the account name.", vbOKOnly + 48, "Warning, Error")
        End If
    Loop Until Len(strNewListItemName) < 31 And Not strNewListItemName = "New Account name." And Not strNewListItemName = ""

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros