View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Jim Thomlinson Jim Thomlinson is offline
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.