#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default InputBox

Using the InputBox (either Excel's method or VBA's function), I'd like the
user to specify a date. But how can I tell if the user has clicked cancel?

Second question: the Excel InputBox allows me to specify the data type.
That's good. But it isn't quite narrow enough (merely 'number' rather than
'date'). Is there a way I can tighten up the data type to 'date'?

Art
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default InputBox

Hi Art

Try

Sub test()
Dim S As String
Dim Dt As Date
Do
S = InputBox("Enter a date:", "Art sez:", S)
If S = "" Then Exit Sub
On Error Resume Next
Dt = DateValue(S)
Loop Until Year(Dt) 1995
MsgBox "You wrote " & Format$(Dt, "dddd mmmm dd. yyyy")
End Sub

It allows all common date formats, e.g. jun 1 and 12/03/04. No specified
year means "this year".

HTH. Best wishes Harald
"ArthurJ" skrev i melding
...
Using the InputBox (either Excel's method or VBA's function), I'd like the
user to specify a date. But how can I tell if the user has clicked cancel?

Second question: the Excel InputBox allows me to specify the data type.
That's good. But it isn't quite narrow enough (merely 'number' rather than
'date'). Is there a way I can tighten up the data type to 'date'?

Art



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default InputBox

Option Explicit
Sub testme()
Dim myDate As Variant
myDate = InputBox(Prompt:="enter a date")
If Trim(myDate) = "" Then
Exit Sub 'user hit cancel
End If

If IsDate(myDate) Then
myDate = CDate(myDate)
Else
MsgBox "not a date"
Exit Sub
End If
End Sub

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

If the user enters 02/03/04, what date do you expect back. (The calendar
control may make it easier to decipher.)

ArthurJ wrote:

Using the InputBox (either Excel's method or VBA's function), I'd like the
user to specify a date. But how can I tell if the user has clicked cancel?

Second question: the Excel InputBox allows me to specify the data type.
That's good. But it isn't quite narrow enough (merely 'number' rather than
'date'). Is there a way I can tighten up the data type to 'date'?

Art


--

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
InputBox GeorgeJ Excel Discussion (Misc queries) 5 July 12th 07 01:20 AM
inputbox brownti via OfficeKB.com Excel Discussion (Misc queries) 2 February 9th 07 02:37 PM
Inputbox and Application.InputBox Maria[_7_] Excel Programming 1 September 20th 04 11:36 AM
inputbox help lothario[_60_] Excel Programming 4 December 7th 03 12:26 AM
inputbox Lawson Excel Programming 2 October 7th 03 08:58 PM


All times are GMT +1. The time now is 09:07 AM.

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

About Us

"It's about Microsoft Excel"