ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Input Box Help - Validate Date Format (https://www.excelbanter.com/excel-programming/339301-input-box-help-validate-date-format.html)

Tbal[_5_]

Input Box Help - Validate Date Format
 

need to code that will validate that the user has input the date (via
InputBox) in the correct format. The user will be prompted to input the
date in the format: Month (first three letters only) [space] Year
(4-digit year), e.g., Jan 2005.

I am having trouble validating the month format. Any suggestions would
be greatly appreciated. I am sure this is basic VBA but I am feeling
VBA-challenged today! :)


--
Tbal
------------------------------------------------------------------------
Tbal's Profile: http://www.excelforum.com/member.php...o&userid=25317
View this thread: http://www.excelforum.com/showthread...hreadid=440421


Dave Peterson

Input Box Help - Validate Date Format
 
Maybe something like:

Option Explicit
Sub testme()

Dim mCtr As Long
Dim myStr As String
Dim okDate As Boolean
Dim FoundMonth As Boolean

okDate = False

Do
myStr = InputBox(prompt:="enter date: mmm yyyy")

If myStr = "" Then Exit Sub 'user hit cancel

okDate = True
If Len(myStr) < 8 Then
okDate = False
ElseIf Mid(myStr, 4, 1) < " " Then
okDate = False
ElseIf IsNumeric(Mid(myStr, 5, 4)) = False Then
okDate = False
Else
FoundMonth = False
For mCtr = 1 To 12
If LCase(Left(myStr, 3)) _
= LCase(Format(DateSerial(2005, mCtr, 1), "mmm")) Then
FoundMonth = True
Exit For
End If
Next mCtr
If FoundMonth = False Then
okDate = False
End If
End If

If okDate = True Then Exit Do
Loop

End Sub

Another option:

You might want to take a look at Ron de Bruin's site for some tips/code/free
calendar control:
http://www.rondebruin.nl/calendar.htm


Tbal wrote:

need to code that will validate that the user has input the date (via
InputBox) in the correct format. The user will be prompted to input the
date in the format: Month (first three letters only) [space] Year
(4-digit year), e.g., Jan 2005.

I am having trouble validating the month format. Any suggestions would
be greatly appreciated. I am sure this is basic VBA but I am feeling
VBA-challenged today! :)

--
Tbal
------------------------------------------------------------------------
Tbal's Profile: http://www.excelforum.com/member.php...o&userid=25317
View this thread: http://www.excelforum.com/showthread...hreadid=440421


--

Dave Peterson


All times are GMT +1. The time now is 02:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com