ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Put Value in a cell next to the active cell (https://www.excelbanter.com/excel-programming/415312-put-value-cell-next-active-cell.html)

Richard

Put Value in a cell next to the active cell
 
Hi

I have a calendar control which populates cells X$3$ to $X$2580. So If I
select cell X$5$ the calendar pops up and I select a date and this is then
entered into cell X5. What I also want to do is put Now() into cell $W$5
I have never used VBA in excel before only in access, so dont know about
active cells

any help greatly appreciated

Thanks

Richard

Bob Phillips[_3_]

Put Value in a cell next to the active cell
 
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "X3:X2580" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target

.Offset(0, -1).Value = Now
.Offset(0, -1).NumberFormat = "dd mmm yyyy hh:mm:ss"
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
__________________________________
HTH

Bob

"richard" wrote in message
...
Hi

I have a calendar control which populates cells X$3$ to $X$2580. So If I
select cell X$5$ the calendar pops up and I select a date and this is then
entered into cell X5. What I also want to do is put Now() into cell $W$5
I have never used VBA in excel before only in access, so dont know about
active cells

any help greatly appreciated

Thanks

Richard





All times are GMT +1. The time now is 04:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com