Force users to enter TEXT ONLY using inputbox method "NEEDED"

love_guy_1977

Board Regular
Joined
Aug 5, 2006
Messages
111
Hi dears,
I need your help to force users to enter TEXT ONLY (From A to Z only) using inputbox method.
Meaning " / % $ & # is not allowed"

Note that I i don't want the user leave the inputbox until he/she enter TEXT even if he/she press No then return bigging of the inputbox.

Thanks in advance
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,

Here is a simple routine to test for text characters. Hope it will help you.

Regards,

Alan

Code:
Sub AscTest()
vText = InputBox("Enter Text")
    If Asc(vText) > 64 And Asc(vText) < 91 Then
        MsgBox "This is a proper Upper case text character"
    ElseIf Asc(vText) > 96 And Asc(vText) < 123 Then
        MsgBox "This is a proper Lower case text character"
    Else
        MsgBox "Invalid entry"
    End If
End Sub
 
Upvote 0
This will not allow the user to exit the inputbox until valid characters are entered and will remove any invalid characters that are typed into the box after OK is hit.

Code:
Public Done As Boolean
Sub test()
Dim x, y As String
Do
SendKeys x
y = InputBox("Enter Text")
x = AlphaOnly(y)
Loop Until Done And y <> ""
End Sub

Function AlphaOnly(r As String) As String
With CreateObject("vbscript.regexp")
    .Pattern = "[^A-Z]"
    .Ignorecase = True
    .Global = True
    Done = Not (.test(r))
    AlphaOnly = .Replace(r, "")
End With
End Function
 
Upvote 0
This will not allow the user to exit the inputbox until valid characters are entered and will remove any invalid characters that are typed into the box after OK is hit.

Code:
Public Done As Boolean
Sub test()
Dim x, y As String
Do
SendKeys x
y = InputBox("Enter Text")
x = AlphaOnly(y)
Loop Until Done And y <> ""
End Sub

Function AlphaOnly(r As String) As String
With CreateObject("vbscript.regexp")
    .Pattern = "[^A-Z]"
    .Ignorecase = True
    .Global = True
    Done = Not (.test(r))
    AlphaOnly = .Replace(r, "")
End With
End Function



Thank you very much
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,153
Members
452,891
Latest member
JUSTOUTOFMYREACH

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