Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default How do I include a date input box in a macro?

I want to record a macro which will show a input box into which I can enter
any date and then continue. I can't find the information in help how to do
this.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default How do I include a date input box in a macro?

Look at Inputbox in help. You will need to validate that the input really is
a date.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Project Mgr" <Project wrote in message
...
I want to record a macro which will show a input box into which I can enter
any date and then continue. I can't find the information in help how to do
this.



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default How do I include a date input box in a macro?

put a sample date in an unused cell of your spreadsheet. record your
macro....

after recording the macro, insert the following lines near the
beginning of your macro


dim usr_date as string 'you can call this whatever you want
usr_date = inputbox("Please enter a date: ")


find where you referenced the unused cell from above (for example
cell B1) and modify the code so that you now reference the usr_date
variable instead


On Jun 19, 9:08 am, Project Mgr <Project
wrote:
I want to record a macro which will show a input box into which I can enter
any date and then continue. I can't find the information in help how to do
this.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 43
Default How do I include a date input box in a macro?

Taking Tim879's response a little further try this:

Dim usr_Date As Date
Dim tempResponse As Variant

ShowDateBox:
tempResponse = InputBox("Please enter date.", "Date Required",
Format(Now(), "dd-mmm-yyyy"))

If tempResponse = "" Then Exit Sub
If IsDate(tempResponse) = False Then GoTo ShowDateBox
usr_Date = tempResponse



usr_Date is a validated response that can be used elsewhere.
tempResponse is a variant to allow for any entry and holds the answer to the
input box, which is then tested for blank or valid date.
A 'Cancel', blank or Null entry stops execution.
If anything other than a date is entered the user is forced back to the
input box.
The above input box also has a default entry of today's date, if you don't
need that remove the 'format' bit to leave
'tempResponse = InputBox("Please enter date.", "Date Required")


HTH
Giz


"Tim879" wrote:

put a sample date in an unused cell of your spreadsheet. record your
macro....

after recording the macro, insert the following lines near the
beginning of your macro


dim usr_date as string 'you can call this whatever you want
usr_date = inputbox("Please enter a date: ")


find where you referenced the unused cell from above (for example
cell B1) and modify the code so that you now reference the usr_date
variable instead


On Jun 19, 9:08 am, Project Mgr <Project
wrote:
I want to record a macro which will show a input box into which I can enter
any date and then continue. I can't find the information in help how to do
this.



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,856
Default How do I include a date input box in a macro?

Here's one I prepared earlier ... (as they say):

Dim check_date As Integer
Dim my_date As String

'some other code

Do Until check_date = vbYes
my_date = ""
Do Until IsDate(my_date)
my_date = InputBox("Please Input date for this download")
Loop
download_date = DateValue(my_date)
check_date = MsgBox("Download Date = " & download_date _
& " - Are you sure?", vbYesNo)
Loop

'rest of code

This gives two levels of validation, as it then used the date to date-
stamp files, so it was important to get the right one.

Hope this helps.

Pete

On Jun 19, 2:08*pm, Project Mgr <Project
wrote:
I want to record a macro which will show a input box into which I can enter
any date and then continue. I can't find the information in help how to do
this.




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default How do I include a date input box in a macro?

THANK YOU, TIM 879. IT SEEMS THAT IT SHOULD WORK, BUT THE DATE DOES NOT SHOW
UP IN THE CELL. HERE IS THE CODE FOR MY ENTIRE MACRO. WHERE IS THE PROBLEM?

Sub DateNeeded()
'
' DateNeeded Macro
' Macro recorded 6/19/2008 by dewey
'
' Keyboard Shortcut: Ctrl+d
'
Selection.NumberFormat = "ddd, mmm d"
Dim usr_date As String 'date
usr_date = InputBox("Please enter date:")
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub

"Tim879" wrote:

put a sample date in an unused cell of your spreadsheet. record your
macro....

after recording the macro, insert the following lines near the
beginning of your macro


dim usr_date as string 'you can call this whatever you want
usr_date = inputbox("Please enter a date: ")


find where you referenced the unused cell from above (for example
cell B1) and modify the code so that you now reference the usr_date
variable instead


On Jun 19, 9:08 am, Project Mgr <Project
wrote:
I want to record a macro which will show a input box into which I can enter
any date and then continue. I can't find the information in help how to do
this.



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default How do I include a date input box in a macro?

Give this a whirl...

Sub DateNeeded()
'
' DateNeeded Macro
' Macro recorded 6/19/2008 by dewey
'
' Keyboard Shortcut: Ctrl+d
'
with Selection
.value = getdate
.NumberFormat = "ddd, mmm d"
.Interior.ColorIndex = 6
End With
End Sub

Public Function GetDate() As Date
Dim strDate As String
Dim blnValidDate As Boolean
Dim dte As Date
Dim strMsg As String

strMsg = "Please enter a date."
blnValidDate = False
Do While blnValidDate = False
strDate = InputBox(strMsg)
On Error Resume Next
GetDate = CDate(strDate)
On Error GoTo 0
If GetDate < 0 Then blnValidDate = True
strMsg = "Invalid date. Please try again."
Loop
End Function
--
HTH...

Jim Thomlinson


"Project Mgr" wrote:

THANK YOU, TIM 879. IT SEEMS THAT IT SHOULD WORK, BUT THE DATE DOES NOT SHOW
UP IN THE CELL. HERE IS THE CODE FOR MY ENTIRE MACRO. WHERE IS THE PROBLEM?

Sub DateNeeded()
'
' DateNeeded Macro
' Macro recorded 6/19/2008 by dewey
'
' Keyboard Shortcut: Ctrl+d
'
Selection.NumberFormat = "ddd, mmm d"
Dim usr_date As String 'date
usr_date = InputBox("Please enter date:")
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub

"Tim879" wrote:

put a sample date in an unused cell of your spreadsheet. record your
macro....

after recording the macro, insert the following lines near the
beginning of your macro


dim usr_date as string 'you can call this whatever you want
usr_date = inputbox("Please enter a date: ")


find where you referenced the unused cell from above (for example
cell B1) and modify the code so that you now reference the usr_date
variable instead


On Jun 19, 9:08 am, Project Mgr <Project
wrote:
I want to record a macro which will show a input box into which I can enter
any date and then continue. I can't find the information in help how to do
this.



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
how do I creat an input form in excel 2007 to include drop down bo DaveH Excel Discussion (Misc queries) 2 May 18th 08 06:40 AM
run macro with input msg based on cell input Janelle S Excel Discussion (Misc queries) 0 January 20th 08 05:23 AM
Need help updating my macro to include a 2nd worksheet. billrl34 Excel Worksheet Functions 0 December 9th 05 08:06 PM
Macro to include contents of cell Matt Excel Discussion (Misc queries) 1 November 15th 05 03:51 AM
Include date in concatenate statement Ken G. Excel Discussion (Misc queries) 3 October 13th 05 05:12 AM


All times are GMT +1. The time now is 05:30 PM.

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"