title: How to calculate time difference (in second) in excel vba for different group of unique values?
body: <p>I know this question appears often previously, but what I have is in the different case. I have some data about date and time which is for two groups. I want to know the duration for each group, but I dont know how to write it in the Excel VBA codes. Could you please help me to solve it?
  Here is my excel sheet. <a href="https://i.stack.imgur.com/fjhv7.png" rel="nofollow noreferrer">enter image description here</a>
  The hard thing is that when in the same group it has changed to other date but when I try to substract the difference, it can be minus not positive. for example :</p>
  
  <pre><code>02.09.2017 19:00:00
  03.09.2017 01:00:00
  </code></pre>
  
  <p>In this case I can't substract 01:00:00 - 19:00:00 because that would be minus, thus I have to consider the change of the date. How can I solve it if it is the case? Thank you very much for the help.</p>