ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   calculate date diff in a cell (https://www.excelbanter.com/excel-programming/349339-calculate-date-diff-cell.html)

Brian Shafer[_2_]

calculate date diff in a cell
 
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



Robin Hammond[_2_]

calculate date diff in a cell
 
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





Brian Shafer[_2_]

calculate date diff in a cell
 
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







Bob Phillips[_6_]

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









Brian Shafer

calculate date diff in a cell
 
Awesome... Thanks

"Bob Phillips" wrote:

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











All times are GMT +1. The time now is 09:01 AM.

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