LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Entering Dates MM/YY only

My input box prompts for MM/YY and then I search for that date in column A.
The dates in column A are in MMMM YYYY format and the actual date is always
the first of that month.

When I tried to search using the results of the input box I got nothing -
because when I type in 10/07 Excel thinks I mean 10/07/2007. So I had to
convert the input to a valid date and make sure it was the first of the month.

Here's my code for the whole thing. Is there a better way for me to do this?

**********************
Private Sub Workbook_Open()
Dim EnterDate As String
Dim FindDate As Date
Dim GoHere As Range

' Prompt user for month and year
EnterDate = InputBox( _
"Enter the Month and Year for the data" & _
" being entered (mm/yy)", _
"Enter MM/YY format", Month(Now()) - 1 & "/" & Right(Year(Now()), 2))

' If date entered is not valid display error msg then display input box
again
Do While Not IsDate(EnterDate) And EnterDate < ""
MsgBox "The value entered is not a date. Please try again."
EnterDate = InputBox("Enter the Month and Year for the data " & _
"being entered (mm/yyyy)", "Enter MM/YYYY format", _
Month(Now()) - 1 & "/" & Right(Year(Now()), 2))
Loop

' Change date to use for searching to be the first of the month entered
If EnterDate = "" Then
MsgBox "User Cancelled"
Else
FindDate = Left(EnterDate, InStr(1, EnterDate, "/") - 1) & "/1/" &
Right(EnterDate, 2)

' Go look in column A for the matching date, move to that cell the
move right two cells
Set rng = Columns(1).Cells
res = Application.Match(CLng(FindDate), rng, 0)
If Not IsError(res) Then
Set GoHere = rng(res)
GoHere.Select
ActiveCell.Offset(0, 2).Select

Else
MsgBox FindDate & " not found"
End If
End If

Exit Sub

addError:

MsgBox "This is not a date."
Resume
End Sub
********************

As always I greatly appreciate the help I get here!!

Lauri S.
 
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
entering dates ownlee4me Excel Discussion (Misc queries) 1 October 8th 09 07:45 PM
Entering Dates Bagia Charts and Charting in Excel 2 May 4th 09 02:55 PM
Entering Dates kmkx70a Excel Discussion (Misc queries) 3 January 22nd 07 03:03 AM
entering dates Ed Excel Discussion (Misc queries) 1 November 26th 06 05:42 PM
Entering dates instructorjml Excel Discussion (Misc queries) 3 March 31st 06 08:20 PM


All times are GMT +1. The time now is 11:24 PM.

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"