VBA to Calculate Date Difference in Days

wazzulu1

Board Regular
Joined
Oct 4, 2006
Messages
164
Hi;

I have a spreadsheet that I need to calculate the date difference in days between each row that has the same LogIn. So I need the date difference in days between row 1 & 2, then 2 & 3, because the LogIn is the same, but row 4 has a new LogIn that would need to begin. The sort would be on the LogIn, then by date in ascending order. I pasted some sample data, just not sure how to do this with VBA.

Appreciate any insight on this if possible, days would be posted in column c.






LogInJP Date
61222181/7/2013
61222185/1/2013
61222185/1/2013
61104169/14/2009
61104167/1/2010
67457931/26/2009
67457931/26/2009
67450451/11/2009
674504511/1/2010
67450453/19/2013
674154710/13/2007
67415475/28/2014
67410565/11/2009
67410567/1/2012
67474832/16/2009
67474838/1/2013
67474837/5/2016
67474837/5/2016
674950512/13/2008
674950510/4/2010
674950510/28/2015
677589212/13/2008
67758928/21/2013
67751965/16/2009
67751966/4/2012
67733282/6/2009
67733288/4/2010
67733285/1/2012
67733283/1/2014
67736201/5/2009
67736207/5/2010
67736202/1/2011
67736203/22/2013
677362011/1/2013
677362011/1/2013

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Got your heart set on VBA rather than a simple formula?
 
Upvote 0
I have my heart set on whatever will work.

Can a formula distinguish the value in column A to correctly calculate the data difference?
 
Upvote 0
Sort by JP Date, then

A​
B​
C​
D​
1​
LogIn
JP Date
Days
2​
6741547​
10/13/2007​
none priorC2: =IFERROR(B2 - LOOKUP(9E+307, B$1:B1 / (A$1:A1=A2)), "none prior")
3​
6749505​
12/13/2008​
none prior
4​
6775892​
12/13/2008​
none prior
5​
6773620​
1/5/2009​
none prior
6​
6745045​
1/11/2009​
none prior
7​
6745793​
1/26/2009​
none prior
8​
6745793​
1/26/2009​
0​
9​
6773328​
2/6/2009​
none prior
10​
6747483​
2/16/2009​
none prior
11​
6741056​
5/11/2009​
none prior
12​
6775196​
5/16/2009​
none prior
13​
6110416​
9/14/2009​
none prior
14​
6110416​
7/1/2010​
290​
15​
6773620​
7/5/2010​
546​
16​
6773328​
8/4/2010​
544​
17​
6749505​
10/4/2010​
660​
18​
6745045​
11/1/2010​
659​
19​
6773620​
2/1/2011​
211​
20​
6773328​
5/1/2012​
636​
21​
6775196​
6/4/2012​
1115​
22​
6741056​
7/1/2012​
1147​
23​
6122218​
1/7/2013​
none prior
24​
6745045​
3/19/2013​
869​
25​
6773620​
3/22/2013​
780​
26​
6122218​
5/1/2013​
114​
27​
6122218​
5/1/2013​
0​
28​
6747483​
8/1/2013​
1627​
29​
6775892​
8/21/2013​
1712​
30​
6773620​
11/1/2013​
224​
31​
6773620​
11/1/2013​
0​
32​
6773328​
3/1/2014​
669​
33​
6741547​
5/28/2014​
2419​
34​
6749505​
10/28/2015​
1850​
35​
6747483​
7/5/2016​
1069​
36​
6747483​
7/5/2016​
0​
 
Last edited:
Upvote 0
hello


I CON NOT FIND TO CREAT NEW POST

HOW I CAN ATTACH PICHER?

THANK YOU
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,041
Messages
6,128,467
Members
449,455
Latest member
jesski

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top