How to automatically add the date to a different cell

mikegoyra

New Member
Joined
Apr 4, 2010
Messages
6
Hello:

I have a spreadsheet where I want to record the start and stop times of certain events, and I thought it would be easy to add a quick script that would automatically put the date in for me. I was mistaken. I used the following script:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 2 Then
Target.Offset(0, -1).Value = Date
End If
End Sub

I wanted to make it so that when any data were added into Column B, the date would appear in Column A automatically. Can anyone assist me here?

Thank you

-Mike
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi Mike,

Welcome to the board!

In what way is it not working? It seems to work fine for me....

Tai
 
Upvote 0
Hello:

The script doesn't really do anything. I saved it, and tried to enter a time into column B, and nothing appeared in column A. So, I tried to close Excel and then reopen it. but that didn't seem to do anything either. I figured I must have coded something incorrectly.

-Mike
 
Upvote 0
Weird... I copied and pasted exactly and it worked.

Did you put in onto a sheet (right-click the tab name, view code, paste in your code) as opposed to a module or on the workbook?

What version of Excel do you have? It seems to work fine on 2000 - maybe someone else on here knows why it might not work on your version...

If you are closing out of Excel altogether, then I think that application.enableevents must be set to true when you re-open Excel. You could try running this (from a module) to be sure, but I doubt that is it.
Code:
sub TurnOnEvents
application.enableevents=true
end sub

Tai
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top