#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Max Max is offline
external usenet poster
 
Posts: 390
Default Date and Time

I have this code so that when I write a name in column A, the date and time
appears both in column B. All I want is that the date appears in column B and
the time in column C. Below is the code.

Thanks in advance.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRow As Long

If Target.Cells.Count 1 Then
Exit Sub 'one cell a time
End If

If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub 'Look in column A only
End If

myRow = Target.Row

On Error GoTo ErrHandler:
With Me.Cells(myRow, "b")
If IsEmpty(.Value) Then
'ok to add, the cell is empty
Application.EnableEvents = False
.NumberFormat = "dd/mm/yyyy hh:mm:ss"
.Value = Now
End If
End With

ErrHandler:
Application.EnableEvents = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,942
Default Date and Time

hi
i edited the code some. tested and works in 03.
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRow As Long

If Target.Cells.Count 1 Then
Exit Sub 'one cell a time
End If

If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub 'Look in column A only
End If

myRow = Target.Row

On Error GoTo ErrHandler:
With Me.Cells(myRow, "b")
If IsEmpty(.Value) Then
'ok to add, the cell is empty
Application.EnableEvents = False
.NumberFormat = "dd/mm/yyyy" ' hh:mm:ss"
.Value = Date
End If
End With
With Me.Cells(myRow, "c")
.NumberFormat = "hh:mm:ss"
.Value = Time
End With

ErrHandler:
Application.EnableEvents = True

End Sub

regards
FSt1


"MAX" wrote:

I have this code so that when I write a name in column A, the date and time
appears both in column B. All I want is that the date appears in column B and
the time in column C. Below is the code.

Thanks in advance.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRow As Long

If Target.Cells.Count 1 Then
Exit Sub 'one cell a time
End If

If Intersect(Target, Me.Range("a:a")) Is Nothing Then
Exit Sub 'Look in column A only
End If

myRow = Target.Row

On Error GoTo ErrHandler:
With Me.Cells(myRow, "b")
If IsEmpty(.Value) Then
'ok to add, the cell is empty
Application.EnableEvents = False
.NumberFormat = "dd/mm/yyyy hh:mm:ss"
.Value = Now
End If
End With

ErrHandler:
Application.EnableEvents = True

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
Calculating days & time left from start date/time to end date/time marie Excel Worksheet Functions 7 December 7th 05 02:36 PM
Combined date time cell to separate date & time components Mark Ada Excel Discussion (Misc queries) 1 December 2nd 04 02:48 AM
Combined date time cell to separate date & time components Mark Ada Excel Discussion (Misc queries) 1 December 2nd 04 12:07 AM
Combined date time cell to separate date & time components Mark Ada Excel Discussion (Misc queries) 1 December 2nd 04 12:07 AM
Combined date time cell to separate date & time components Mark Ada Excel Worksheet Functions 1 December 2nd 04 12:04 AM


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