Qualifying macro run according to current selection

N

Neil

Hi all,

For some reason this very simple macro is causing me grief:

I have two date fields adjacent to a macro button.

If the user presses the button, I would like the currently selected date
field (one of the two adjacent) to be filled in with the current date, ie,
'=now()' - however I do not want this field 'live' - it should only contain
the date when the macro was activated.

Normally I would do this by pasting in the equation with the macro, then
copying the selected date range and pasting over itself - values only, I'm
sure there is probably a more elegant way....

Obviously if the current selection is not one of the two date fields, I will
flag this via a MsgBox statement and exit the sub.

Your assistance in proposing a simple code to achieve the above is greatly
appreciated.

Thanks.

Neil
 
R

Ron de Bruin

Try this

Sub test1()
If Not Application.Intersect(Range("C1"), ActiveCell) Is Nothing Then
ActiveCell.Value = Date
Else
MsgBox "Please select the date cell"
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top