Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Date Time Question

I have the following on my spreadsheet:

A1 = Date
A5 = Begin Time
A6 = End Time
A7 = A1+A5 'Giving me the Beginning Date & Time
A8 = A1+A6 'Giving me the End Date & Time

What I want to do is whenever the user enters a time in Cell A9, either a
data validation or vba check that time entered is between the value in Cell
A7 and A8. The assumption is that the value in Cell A9 is A9+A1 but I only
want the user to only enter the time. It is probably easier just to have a
format of Date/Time throughout but I am constraint by the design format. I
tried with the validation with a custom formula: = AND(A9+A1A7, A9+A1<A8).
This just gave me a error for any number I entered. And I tried a event
procedu

If Target.Column = 15 And Target.Row = 10 Then
If Target.Value + Target.Offset(-9, 2).Value
Target.Offset(-1, 0).Value And Target.Value + Target.Offset(-9, 2).Value
Target.Offset(-1, 1) Then
Target.Value = Target.Value
Else
MsgBox ("Time entered does not fall within work shift.")
Target.Value = " "
Exit Sub
End If
End If
End Sub

Cell

--
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
Sox Sox is offline
external usenet poster
 
Posts: 4
Default Date Time Question


"Daviv" wrote in message
...
I have the following on my spreadsheet:

A1 = Date
A5 = Begin Time
A6 = End Time
A7 = A1+A5 'Giving me the Beginning Date & Time
A8 = A1+A6 'Giving me the End Date & Time

What I want to do is whenever the user enters a time in Cell A9, either a
data validation or vba check that time entered is between the value in
Cell
A7 and A8. The assumption is that the value in Cell A9 is A9+A1 but I
only
want the user to only enter the time. It is probably easier just to have
a
format of Date/Time throughout but I am constraint by the design format.
I
tried with the validation with a custom formula: = AND(A9+A1A7,
A9+A1<A8).
This just gave me a error for any number I entered. And I tried a event
procedu

If Target.Column = 15 And Target.Row = 10 Then
If Target.Value + Target.Offset(-9, 2).Value
Target.Offset(-1, 0).Value And Target.Value + Target.Offset(-9, 2).Value
Target.Offset(-1, 1) Then
Target.Value = Target.Value
Else
MsgBox ("Time entered does not fall within work
shift.")
Target.Value = " "
Exit Sub
End If
End If
End Sub

Cell

--
Thanks!



Private Sub Worksheet_Change(ByVal target As Range)

myRow = target.Row ' Remember row of changed cell
myCol = target.Column ' Remember column of changed cell
myValue = target.Value ' Remember user entered time

If myValue = "" Then Exit Sub ' If cell null by this routine, do not get
into endless loop

' No sense doing this check if cell A9 is not the one that changed
If myRow = 9 And myCol = 1 Then

' Assumption is that value to check is the date in cell A1 PLUS the user
entered value
chkValue = target.Value + Cells(1, 1).Value

' Make a string for later use if this is a bad value
myText = Format(myValue, "hh:mm AMPM")

' Use the worksheet to get the minimum and maximum acceptable values
minValue = Cells(7, 1).Value
maxValue = Cells(8, 1).Value

' Now check to see if user input is good -- if not, set to null string
and prompt user
If chkValue < minValue Then
MsgBox "Time " & myText & " is too early - please re-enter"
Cells(9, 1).Value = ""
Else
If chkValue maxValue Then
MsgBox "Time " & myText & " is too late -- please re-enter."
End If
End If
End If

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
Time and Date Question wx4usa Excel Discussion (Misc queries) 6 October 8th 07 03:34 AM
Another question about time and date ECLynn Excel Discussion (Misc queries) 2 August 30th 06 10:13 PM
Date Time Question srroduin Excel Programming 3 May 24th 06 05:32 PM
Date/Time Question bladelock Excel Worksheet Functions 2 November 10th 05 02:42 AM
date/time question mk Excel Programming 5 June 7th 05 12:32 PM


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