Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date input format Roy Gudgeon[_2_] Excel Discussion (Misc queries) 2 May 20th 10 02:05 PM
Trying to validate input based upon values in two other cells JG Excel Discussion (Misc queries) 1 December 11th 09 05:49 PM
TEXTBOX - VALIDATE DATE INPUT Steve_G Excel Programming 3 June 12th 05 04:59 AM
how to format a date/validate for a text box entry on a user form Tom Ogilvy Excel Programming 3 June 1st 05 05:06 PM
How can I validate data input by macros? ewan72 Excel Programming 2 February 23rd 05 04:13 PM


All times are GMT +1. The time now is 02:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"