add a date to an excel field upon data input in specific range

Guys, I am after some help, I am after some code that when you enter any data in a range  cells A1 to A20 that the adjacent cell B1 to B20 adds todays date

so if I enter into cell A5 then B5 will add todays date then if I entered another value in cell A19 tomorrow then B19 will have that date.

But the other dates that are already there don't alter unless that field that already has data init gets altered.

Any Ideas
DarrenJacksonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
>>so if I enter into cell A5 then B5 will add todays date then if I entered another value in cell A19 tomorrow then B19 will have that date.

can you provide examples what values are you entered in column A and what are the expected results in column B ?
0
DarrenJacksonAuthor Commented:
Wow thanks for the fast response

The column A will always be a date   01/01/2015  as an example  in column B it will return the date of the day it was entered
ie
A                       B
01/01/2015     22/10/2015
04/07/2014     21/10/2015     ***  if this was entered yesterday ****
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Right click on the Sheet Tab --> View Code --> Paste the code given below into the opened code window --> Save your workbook as Macro-Enabled Workbook.
Dim pVal
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Intersect(Target, Range("A1:A20")) Is Nothing Then
   If Target.Offset(0, 1) = "" And Target <> paval Then
      Target.Offset(0, 1) = Format(Now, "mm/dd/yyyy")
   End If
End If
Application.EnableEvents = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("A1:A20")) Is Nothing Then
   pVal = Target.Value
End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

DarrenJacksonAuthor Commented:
Wow thanks for the quick responses. This is perfect thankyou very very much
0
Ryan ChongCommented:
I have put "Entered Date" into column B and "Updated Date" into column C, in case you need it...

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim r As Range
    For Each r In Target
        If r.Column = 1 And r.Row > 1 Then
            'Updated date
            If r.Offset(0, 1) <> "" And r.Offset(0, 2) = "" Then
                r.Offset(0, 2) = Date
            End If
            'Entered date
            If r.Offset(0, 1) = "" Then
                r.Offset(0, 1) = Date
            End If
        End If
    Next
End Sub

Open in new window

28763359.xlsm
0
DarrenJacksonAuthor Commented:
Ryan thank you also. didn't see your post until I accepted the other.

But I very much appreciate your post

Thankyou
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Darren! Glad I could help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.