Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Date input format | Excel Discussion (Misc queries) | |||
Trying to validate input based upon values in two other cells | Excel Discussion (Misc queries) | |||
TEXTBOX - VALIDATE DATE INPUT | Excel Programming | |||
how to format a date/validate for a text box entry on a user form | Excel Programming | |||
How can I validate data input by macros? | Excel Programming |