![]() |
|
#2
|
|||
|
|||
|
Hi
Your code has separated the two column routines completely. It worked if you clicked column B, but if you clicked column D, it checked if column B was the target and if it wasn't the whole routine terminated. Here is how I would do it Cheers Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim BCol As Range, DCol As Range
Set BCol = Range("B:B")
Set DCol = Range("D:D")
' If any errors occur make sure Enable Events is on when macro exited
On Error GoTo ExitOut
If Not Intersect(Target, BCol) Is Nothing Or Not Intersect(Target, DCol) Is Nothing Then
Application.EnableEvents = False
If Target.Row >= 2 Then ' Minimum of row 2
With Target.Offset(, 1) ' Put date & time in adjacent column to the right
.Value = Now
.NumberFormat = "dd/mm/yyyy hh:mm:ss" ' Change to suit
End With
GoTo ExitOut
End If
End If
GoTo ExitOut
ExitOut:
On Error GoTo 0
Application.EnableEvents = True
Exit Sub
End Sub
|
| Tags |
| date/time, vba code |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Day date and time cell display | markg2 | Excel | 2 | 02-11-2015 06:57 AM |
date & time of last time a recent file was used
|
pgeorgilas | Word | 1 | 10-31-2014 08:59 AM |
| Date/Time Formula for Entry level XL user | talon1driver | Excel | 2 | 09-18-2014 02:32 PM |
| Count the common time period (month) between two date period of time | Barni | Excel | 6 | 08-15-2014 07:52 AM |
Sent emails all have same date/time??
|
Confused | Outlook | 3 | 01-07-2011 07:52 AM |