Reputation: 27
Hello guys I am completely stumped as to why this bit of code is not working. Can anybody help?
Sub test()
Dim RpDate As Variant
Dim x As String
RpDate = InputBox("Enter Date", "Date")
If RpDate = "" Then Exit Sub
x = Day(RpDate)
MsgBox x
End Sub
Upvotes: 0
Views: 95
Reputation: 33692
You could force the InputBox
to allow only Date
type valid values, try the code below:
Option Explicit
Sub InputBoxDateFormat()
Dim RpDate As Date
Dim x As Integer
' InputBox that allows only dates
RpDate = Application.InputBox("Enter Date", "Date", FormatDateTime(Date, vbShortDate), Type:=1)
' "Cancel" was selected
If RpDate = 0 Then Exit Sub
x = Day(RpDate)
MsgBox x
End Sub
Upvotes: 1