ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   date column (https://www.excelbanter.com/excel-programming/290127-date-column.html)

jamie85[_11_]

date column
 
I want a date column which shows the date of when data was entered in
that row. How is this done? Thanks.


---
Message posted from http://www.ExcelForum.com/


Tom Ogilvy

date column
 
This uses column 3 (C) as the date column. Right click on the sheet tab and
select view code. Paste in code like this:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler:
If Target.Count 1 Then Exit Sub
If Target.Column < 3 Then
Application.EnableEvents = False
Cells(Target.Row, 3).Value = Now
Cells(Target.Row, 3).NumberFormat = "mm/dd/yy hh:mm"
Columns(3).AutoFit
End If
ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy

"jamie85 " wrote in message
...
I want a date column which shows the date of when data was entered in
that row. How is this done? Thanks.


---
Message posted from http://www.ExcelForum.com/




jamie85[_12_]

date column
 
Great thanks i have edited the code to suit as follows:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler:
If Target.Count 1 Then Exit Sub
If Target.Column < 11 Then
Application.EnableEvents = False
Cells(Target.Row, 11).Value = Now
Cells(Target.Row, 11).NumberFormat = "mm/dd/yy hh:mm"
Columns(11).AutoFit
End If
ErrHandler:
Application.EnableEvents = True
End Sub

What would i have to change so the code would only apply to cells K2
K30 ? Thank

--
Message posted from http://www.ExcelForum.com


jamie85[_13_]

date column
 
Great thanks i have edited the code to suit as follows:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler:
If Target.Count 1 Then Exit Sub
If Target.Column < 11 Then
Application.EnableEvents = False
Cells(Target.Row, 11).Value = Now
Cells(Target.Row, 11).NumberFormat = "mm/dd/yy hh:mm"
Columns(11).AutoFit
End If
ErrHandler:
Application.EnableEvents = True
End Sub

What would i have to change so the code would only apply to cells K2
K30 ? Thank

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

date column
 
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler:
If Target.Count 1 Then Exit Sub
If Not Intersect(Range("K2:K30"),Target) is nothing Then
Application.EnableEvents = False
Cells(Target.Row, 11).Value = Now
Cells(Target.Row, 11).NumberFormat = "mm/dd/yy hh:mm"
Columns(11).AutoFit
End If
ErrHandler:
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy


jamie85 wrote in message
...
Great thanks i have edited the code to suit as follows:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ErrHandler:
If Target.Count 1 Then Exit Sub
If Target.Column < 11 Then
Application.EnableEvents = False
Cells(Target.Row, 11).Value = Now
Cells(Target.Row, 11).NumberFormat = "mm/dd/yy hh:mm"
Columns(11).AutoFit
End If
ErrHandler:
Application.EnableEvents = True
End Sub

What would i have to change so the code would only apply to cells K2 -
K30 ? Thanks


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 06:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com