![]() |
Qualifying macro run according to current selection
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 |
Qualifying macro run according to current selection
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 -- Regards Ron de Bruin http://www.rondebruin.nl/tips.htm "Neil" wrote in message ... 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 |
All times are GMT +1. The time now is 09:52 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com