Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 03-06-2016, 10:12 PM
Philb1 Philb1 is offline Date/Time Entry Windows 10 Date/Time Entry Office 2010 32bit
Advanced Beginner
 
Join Date: Feb 2016
Location: Auckland
Posts: 43
Philb1 is on a distinguished road
Default

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
Reply With Quote
 

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 Entry 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
Date/Time Entry Sent emails all have same date/time?? Confused Outlook 3 01-07-2011 07:52 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:45 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft