Learn Excel 2010 - "Date Stamp Next to a Yes": Podcast #1474

If you like this content, please consider visiting the video on YouTube and subscribe to the MrExcel Channel to show your support!
This video has been published on Nov 21, 2011.
Superbeast326 at YouTube asks if there is a way to add the current date to the right of any 'Yes' entries in a spreadsheet; if a cell is marked 'Yes', then I want the cell to the right of that cell to show the date. Using a simple 'Event Handler' macro, in Episode #1474, Bill creates a means to answer the question and record the date.

...This blog is the video podcast companion to the book, Learn Excel 2007 through Excel 2010 from MrExcel. Download a new two minute video every workday to learn one of the 512 Excel Mysteries Solved! and 35% More Tips than the previous edition of Bill's book!

"The Learn Excel from MrExcel Podcast Series"

MrExcel.com — Your One Stop for Excel Tips and Solutions. Visit us today!
maxresdefault.jpg


Transcript of the video:
MrExcel podcast is sponsored by Easy-XL.
Learn Excel from MrExcel podcast, episode 1474: date next to yes.
Today’s question is sent in on YouTube.
Superbeast326 says, “Anytime I enter the word yes, I want the cell to the right of it to show the date that that yes was entered.” As I think about this, he probably has a column, right?
There's probably a column that he's going to be entering that in because I can't imagine he would just want it to work everywhere.
So, I'm going to remember here that we want this to work if the yes is in column D, which is the fourth column.
All right, so I’m going to switch over to VBA with Alt F11, in the project explorer we're going to find the worksheets on-- right here on Sheet1.
Double-click, left drop-down choose worksheet, right drop-down we're going to choose every time they change the worksheet.
I'm guessing that he's going to be entering the word yes.
It's not going to be as a result of a formula.
If it was the result of a formula, we would use calculate as we did I think last Thursday.
So, target is a variable, an object variable.
That is the cell that was just changed.
So, if target dot value is equal to 4-- I'm sorry.
If target dot column is equal to 4, then-- in other words, that’s saying if the cell that just changed is in column D, ABCD, then if target dot value is equal to yes-- now, were they entering uppercase, lowercase?
I don’t know.
So, let's convert whatever they entered into lowercase, not in the cell, but just here in VBA.
So, in the spreadsheet, we would use lower, in VBA they use LCase for lower.
All right, if all of that is true, then we want to go to the cell to the right and enter the current date.
We're not going to actually go to that cell.
We're just going to enter the date in that cell to the right.
So, target, that's a variable again, dot offset zero rows down one column over dot value is equal to date.
End if and end if.
This little bit of code is called an event handler macro.
Every time someone changes, the worksheet is going to go do all this.
Now, this is actually going to run a little bit slow because when we change the worksheet to put the date in, it's going to run the code a second time.
So, let's just say right here: application dot enable events is equal to false and then after we enter the date, copy that and paste.
This just prevents the macro from running twice every single time that someone changes a cell.
All right, so we come out here to column F, we enter something, nothing happens.
Enter yes in column F, nothing happens.
In column D enter no, nothing happens.
Enter yes in column D and we get the date.
Very, very sweet trick; works with uppercase, works with upper and lower case.
Works with any way you want to enter yes.
That's going to give you that data.
It will work anywhere in column D. You can page down all the way down here and enter yes and there's a date.
Look how fast it runs.
You can’t even see the screen flash.
It's just like magic, just like magic.
So, hey, I want to thank Superbeast for sending that question in and I want to thank you for stopping by.
We'll see you next time for another netcast from MrExcel.
 

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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