Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Worksheet_Change: Date Time Input [mmddyy hhmm] to [mm/dd/yy

Dave Peterson wrote:
How about this:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

'MMDDYY HHMM
Dim myRng As Range
Dim myCell As Range
Dim myMonth As Long
Dim myDay As Long
Dim myYear As Long
Dim myHour As Long
Dim myMin As Long

Set myRng = Me.Range("a1:A999")

If Intersect(myRng, Target) Is Nothing Then
Exit Sub
End If

For Each myCell In Intersect(myRng, Target).Cells
With myCell
If .Value Like "###### ####" Then
'keep going
myMonth = Mid(.Value, 1, 2)
myDay = Mid(.Value, 3, 2)
myYear = Mid(.Value, 5, 2)
If myYear < 31 Then
myYear = myYear + 2000
Else
myYear = myYear + 1900
End If
myHour = Mid(.Value, 8, 2)
myMin = Mid(.Value, 10, 2)

If Format(DateSerial(myYear, myMonth, myDay) _
+ TimeSerial(myHour, myMin, 0), "mmddyy hhmm") _
= .Value Then
'it's ok
Application.EnableEvents = False
.Value = DateSerial(myYear, myMonth, myDay) _
+ TimeSerial(myHour, myMin, 0)
.NumberFormat = "mmddyy hhmm"
Application.EnableEvents = True
End If
End If
End With
Next myCell

End Sub

=======
And for the .formula vs .value in Chip's code. I'd just say he wrote each
procedure at different times.

Since he does this:

If .HasFormula = False Then

He knows that the .value and .formula return the exact same thing.

Brian Handly wrote:
WinXP SP2, Excel XP

I found Chip Pearson's Date Time help:
(http://www.cpearson.com/excel/DateTimeEntry.htm)

However, his Worksheet_Charge example VBA Subroutines are either for
Dates or Times.

I need to handle Date + Time in the same field.

I have tried to combine Chip's two example Subroutines into one, but
have not managed to make a single Subroutine that will handle inputs
like "MMDDYY HHMM" [preferred input]

I have not been able to figure out why Chip's Datevalue Sub uses
".Formula" and the TimeValue Sub uses ".Value" when extracting the user
input.

Suggestions?

Texas Handly


Dave

Thanks, Especially for your response on .Formula vs .Value

I will try the Subroutine.

Texas Handly
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 to Input date & Time [NOW()], then stop it updating? jonathandr Excel Worksheet Functions 3 October 23rd 06 05:41 PM
Recording Time & Date based on data input Lady Success Excel Worksheet Functions 2 October 19th 06 01:51 PM
changing the format for the time shen entered as HHMM to HH:MM QD Excel Discussion (Misc queries) 2 September 5th 06 12:21 AM
How do you change a date that is in the yyyymmdd format to mmddyy Norton Excel Discussion (Misc queries) 2 March 8th 06 03:15 PM
time specific date input Ron Albert Excel Programming 1 January 18th 04 11:54 AM


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