Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Using Macros to ask the user to enter a date

Is there a way to program a macro so that when it is run, first a
window pops up asking the user to enter in a date. Could I then use
this date in the same macro? (i.e. I want to just pull the data that
was entered in the month the user requests). Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Using Macros to ask the user to enter a date

Dim dt As Date
dt = InputBox("Enter date (mm/dd/yy).")

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Using Macros to ask the user to enter a date

One way:

Dim vDate As Variant
Do
vDate = Application.InputBox( _
Prompt:="Enter date:", _
Title:="MyMacro", _
Default:=Date)
If vDate = False Then Exit Sub 'user cancelled
Loop Until IsDate(vDate)
'Do more stuff


In article .com,
wrote:

Is there a way to program a macro so that when it is run, first a
window pops up asking the user to enter in a date. Could I then use
this date in the same macro? (i.e. I want to just pull the data that
was entered in the month the user requests). Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Using Macros to ask the user to enter a date

for flexibility on input formats:

Sub demo()
Dim d As Date
d = DateValue(Application.InputBox("Enter Date: ", 2))
MsgBox (d)
End Sub

--
Gary's Student
gsnu200705


" wrote:

Is there a way to program a macro so that when it is run, first a
window pops up asking the user to enter in a date. Could I then use
this date in the same macro? (i.e. I want to just pull the data that
was entered in the month the user requests). Thanks!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Using Macros to ask the user to enter a date

Note, though, that this throws a run-time error if the user cancels or
enters a non-date (including a blank). It's a little more user-friendly
to use something like:

Public Sub Demo()
Dim d As Date
Dim vAnswer As Variant
Do
vAnswer = Application.InputBox("Enter date", "Title")
If vAnswer = False Then Exit Sub 'user cancelled
Loop Until IsDate(vAnswer)
d = CDate(vAnswer)
MsgBox d
End Sub


In article ,
Gary''s Student wrote:

for flexibility on input formats:

Sub demo()
Dim d As Date
d = DateValue(Application.InputBox("Enter Date: ", 2))
MsgBox (d)
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Using Macros to ask the user to enter a date

Thank you for the advice
--
Gary's Student
gsnu200705


"JE McGimpsey" wrote:

Note, though, that this throws a run-time error if the user cancels or
enters a non-date (including a blank). It's a little more user-friendly
to use something like:

Public Sub Demo()
Dim d As Date
Dim vAnswer As Variant
Do
vAnswer = Application.InputBox("Enter date", "Title")
If vAnswer = False Then Exit Sub 'user cancelled
Loop Until IsDate(vAnswer)
d = CDate(vAnswer)
MsgBox d
End Sub


In article ,
Gary''s Student wrote:

for flexibility on input formats:

Sub demo()
Dim d As Date
d = DateValue(Application.InputBox("Enter Date: ", 2))
MsgBox (d)
End Sub


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
Defining user access (via user id) using macros maruko Excel Discussion (Misc queries) 0 July 27th 09 02:44 AM
Enter a User Name When Changes are Made chickalina Excel Worksheet Functions 4 July 30th 08 05:05 PM
Restricting user to enter the date in a particular format only ! sajjadhyder Excel Discussion (Misc queries) 1 January 3rd 08 05:25 PM
Auto enter date when data in enter in another cell Brian Excel Worksheet Functions 5 December 7th 06 06:44 PM
Getting user to enter file name kuansheng Excel Programming 9 March 13th 06 05:55 AM


All times are GMT +1. The time now is 07:14 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"