Put Value in a cell next to the active cell

R

richard

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
 
B

Bob Phillips

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.
 

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