Excel 2010: Date Cell Automation

Hello Experts!

    I'm curious if any one has (or can point me to) a formula or some .vba that I can use that automate the following process:  I'd like it to do an Alt+Enter in ONE cell that contains dates that are vertical of one another and then add the present date (mm/dd/yyyy) at the bottom.  It can be int he form of a button, you click and it does this or as soon as you click into the cell e.g.
 
  Column K
***********************************
* 7/1/2015                                                     *
* 7/2/2015                                                     *
* 7/3/2015                                                     *
* 7/4/2015                                                     *
* 7/5/2015                                                     *
* 7/28/2015 <--present date added          *       <-----ONE Cell, let's call this K2 as an example.
***********************************


Any help is GREATLY appreciated!  Thank you.
itsmevicAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Wayne Taylor (webtubbs)Commented:
You can use the SelectionChange event to accomplish this...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = [A1].Address Then
        Target.Value = Target.Value & vbCrLf & Date
    End If
End Sub

Open in new window


This code will go in the applicable worksheets code module (right-click tab > View Code). It will append the current date to the value already present in cell A1 (modify to suit).
itsmevicAuthor Commented:
I went into the code.  I see Sheet 1 which is my Raw Data sheet where I want to place the code at.  I right click on Sheet1 (Raw Data) and select Insert > Module.  It inserts the Module.  I then double-click on the module to go into it.  I then right click and paste the code.   I click Save.   I then click the green arrow to run the macro, It pops open the macro dialog box and wants me to give it a name.  I give it the name "test" it then adds "test" as a sub. e.g.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = [k78].Address Then
        Target.Value = Target.Value & vbCrLf & Date
    End If
End Sub
_____________________________________________________________________________
Sub test()

End Sub

It's been a while since I've messed with this stuff, obviously I'm doing something wrong...
Wayne Taylor (webtubbs)Commented:
No, it goes into the sheet's module, not a general module as you have done. The easiest way to get to the worksheet code module is to right-click the tab in the main Excel window and select "View Code". Otherwise, while in the VBE, double click the worksheet in the project explorer.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

SteveCost AccountantCommented:
Try this code and then set it to run on keyboard shortcut:
(pop it in a normal module)

Sub addTodayToBottom()

Cells(ActiveCell.End(xlDown).Row + 1, ActiveCell.Column).Value = Date

End Sub

Open in new window

SteveCost AccountantCommented:
Or this one can be less buggy:

Sub addTodayToBottom()

Cells(Range(Cells(Rows.Count, ActiveCell.Column), Cells(Rows.Count, ActiveCell.Column)).End(xlUp).Row + 1, ActiveCell.Column).Value = Date

End Sub

Open in new window

Wayne Taylor (webtubbs)Commented:
Steve, you're missing the vital requirement. The date is appended to the value already in the selected cell.
SteveCost AccountantCommented:
No... the way I read this:

I'd like it to do an Alt+Enter in ONE cell that contains dates that are vertical of one another and then add the present date (mm/dd/yyyy) at the bottom.

Is that the date should be appended to the bottom of the currently selected column.
Not the currently selected cell.
Wayne Taylor (webtubbs)Commented:
in ONE cell

Note the bolded ONE and the diagram. Plus Alt+Enter inserts a carraige return in a cell.
SteveCost AccountantCommented:
AH, I stand corrected... I totally mis-understood.

I would tend not to use the 'on change event' as it may add too many dates to the cell:

Sub addTodayToCell()

ActiveCell.Value = Activecell.value & vbCrLf & format(Date,"mm/dd/yyyy")

End Sub

Open in new window

itsmevicAuthor Commented:
Great feedback, thank you guys.  I'm going to actually end up using both code sets.

Wayne, for your code, I need the macro to encompass each cell on down starting at K78, what would be the proper syntax so that each cell in column K is going to do what the code below says?  I just threw in the k200 as an example.  I'm sure you understand what I"m try to describe.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address = [k78; k200].Address Then
        Target.Value = Target.Value & vbCrLf & Date
    End If
End Sub
itsmevicAuthor Commented:
Steve - Thanks for your input, for your code, let's say I just wanted to do it 'on click' rather than having to use a short cut key?  Is there an OnClick variable we could add to your code and it do the same function as you've programmed it to thus far?  I'm in and out of these cells a lot, to be able to just click on it and bam! it do the alt+enter, add present date to the bottom of that cell would be priceless, at least in my case it would be.
SteveCost AccountantCommented:
You could put it in the double click event:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

ActiveCell.Value = Activecell.value & vbCrLf & format(Date,"mm/dd/yyyy")

End Sub

Open in new window

This may do what you want... (needs to be in worksheet module)
Wayne Taylor (webtubbs)Commented:
itsmevic,

To allow my code to operate on a range of cells, you can use the Intercept function...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, [K78:K200]) Is Nothing Then
        Target.Value = Target.Value & vbCrLf & Date
    End If
End Sub

Open in new window


Note that this does the same as Steve's code above but without the double-click.

Wayne

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
itsmevicAuthor Commented:
Fantastic!  If I could give you both 1000 points I would!  Unfortunately, we'll have to settle and are limited to a measly 250 points each.  :(

I'm using both macros now as I like the subtle differences in each.  Again, thanks guys!
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.