Microsoft Office Tutorials and References
In Depth Information
Restricting Text Box Entry to Numbers
' * * * * *¶
Public Sub Display(ByVal Target As Range)¶
'Make sure that only one cell was received¶
Set Target = Target(1)¶
If IsDate(Target.Value) Then¶
mChoice = Target.Value¶
mChoice = Date¶
End If¶
Calendar1.Value = CDate(mChoice)¶
End Sub¶
' * * * * *¶
Public Property Get GetChoice() As Variant¶
GetChoice = mChoice¶
End Property¶
Notes: The procedure uses the BeforeDoubleClick event of a worksheet module to
display the UserForm.
This procedure is designed to operate only in column A. This restriction can be
changed to limit the functionality to whatever cells are required.
In the Example file, the macro runs when a cell in column A is double-clicked,
but the macro can also be called from a button.
The calendar control used in the UserForm requires a reference to be set in
the VBE. There are examples of VBA-only calendar controls that perform in the
same manner at and
Restricting Text Box Entry to Numbers
This procedure shows you how to ensure that a UserForm text box accepts only
a numeric entry.
Example file:
Scenario: For an application that uses a UserForm—say a
loan calculator—some code is required to make sure that the
user enters only actual numbers in the textboxes. This
reduces errors. The example shows how to control the input
from the source, meaning at the same time that the user is
entering the data into the textbox.
Search JabSto ::

Custom Search