date - time parsing code

  • Thread starter Thread starter mgm
  • Start date Start date
M

mgm

cpearson directed me to working code to correctly parse the time and date
formats.. it works great when only either date or time is used as a
worksheet_change. How can I add a second worksheet_change for the cells that
have date? (the time cells already have the procedure)
Thanks chuck... wonderful site
 
You only get one worksheet_change event per worksheet.

But you could do different things if you can define when times or dates should
be applied.

For instance, if the dates go in column A and the times go in column B, you
could set up the code that way.

Kind of...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub

If Not Intersect(Target, Me.Range("a:a")) Is Nothing Then
'process as a date (column A)
Else
If Not Intersect(Target, Me.Range("b:b")) Is Nothing Then
'process as a time (column B)
Else
'do nothing
End If
End If

End Sub



But if your dates are intermixed (randomly) in the same column, you'd have to
something different--maybe add an indicator character that says to treat this
entry as a time or treat it as a date.
 
Back
Top