View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default calculate date diff in a cell

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Row = 1 And Target.Column 1 Then
With Target
.Offset(1, 0).Value = .Value - .Offset(0, -1).Value
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 Phillips

(remove nothere from email address if mailing direct)

"Brian Shafer" wrote in message
...
yes, you are right.. but I want it to happen automatically when I enter a
valid date in t b1 write the diff in b2

"Robin Hammond" wrote in message
...
Brian,

If I understand you correctly (and I probably don't)

in a1 you have a value: 2006/01/01
in a2 you have a value: 2006/01/03

in b2 for days difference: =A2-A1

Robin Hammond
www.enhanceddatasystems.com

"Brian Shafer" wrote in message
...
Hi.
I have a spread sheet that contains in the first column a date time
formatted field, in a few columns over, I have a field that I would

like
to automatically calculate the days between the current rows date field
and the previous rows date field and put the number of days different

in
the days diff column. Can anyone help me with this...?
Thanks,
Brian Shafer