title: Creating Macro for Copying data from one sheet to another,calculating the difference between dates in excel
body: <p>The below mentioned data is for door access in a company where in we need to find the number of hours spent by a employee in office.</p>
  
  <p>A employee can come in the office and swipe in and swipe out multiple times and all these details are register in the excel in non sorted order for all the employees.</p>
  
  <p>I have a excel containing multiple columns </p>
  
  <p>First two columns A,B are merged cells having date in this format(2015/01/25  7:27:30 PM).</p>
  
  <p>The third column C has Access information having multiple entries for the below values(Entry/Exit).</p>
  
  <p>For example </p>
  
  <pre><code>Column A Column B            Access Employee ID    Employee Name
  ==================================================
  
   1. 2015/01/25  7:27:30 AM      Entry     111          XYZ 
  
   2. 2015/01/25 7:30:30 AM       Entry     333           ABC 
   3. 2015/01/25  8:30:30 AM      Exit      111          XYZ
   4. 2015/01/25  9:30:30 AM      Entry     111          XYZ 
   5. 2015/01/25  9:30:30 AM      Entry     444          PQR
  
   6. 2015/01/25  10:30:30 Pm     Exit      333          ABC 
   7. 2015/01/26  7:30:30 AM      Exit      333          ABC
  </code></pre>
  
  <p>And so on.</p>
  
  <p>Please note that the same employee can have multiple swipe in and out's throughout the day and will be clobbered among other employees information
  The Goal is to as below
  1) Copy the data from one sheet to another for the employees having spent time less than 9 hours for a specific day.</p>
  
  <p>Here is the sample code that i have written it is work in progress </p>
  
  <pre><code>Sub HoursList()
  
    Dim cell As Range
    Dim cell1 As Range
  
    Dim NewRange As Range
    Dim NewRange1 As Range
  
    Dim MyCount As Long
  
    Dim ExistCount As Long
  
    Dim ExistsCount As Boolean
  
    Dim temp As Long
      Dim MyCount1 As Long
  
  
    Dim wsh As Worksheet, i As Long, lngEndRowInv As Long
    Set wsh = Worksheets("Standard Door History          ")
    'Set cell = Range("A1")
  
    ExistCount = 0
    ExitsCount = False
  
    MyCount = 1
  
  MyCount1 = 1
  
  
  
  
  
  i = 12
  lngEndRowInv = wsh.Range("P" &amp; wsh.Rows.Count).End(xlUp).Row
  
  
  
  
  '----For every cell in row G on the  Data sheet----'
  
  For Each cell In wsh.Range("C12:D9085")
  
   If cell.Value = "Entry" Then
  
  
        'ExistCount = ExistCount + 1
  
       If MyCount = 1 Then Set NewRange = cell.Offset(0, -1)
        '----Sets up a new range to copy all data from the row if column in that row contains the value in question----'
  Set NewRange = Application.Union(NewRange, cell.EntireRow)
  
       MyCount = MyCount + 1
  End If
  
  
  
  Next cell
  
  
  For Each cell1 In NewRange
  
     If cell1.Value = "Mayur" Then
  
      If MyCount1 = 1 Then Set NewRange1 = cell.Offset(0, -1)
        '----Sets up a new range to copy all data from the row if column  in that row contains the value in question----'
  Set NewRange1 = Application.Union(NewRange1, cell.EntireRow)
  
       MyCount1 = MyCount1 + 1
  
  End If
  Next cell1
  
  If ExistCount &gt; 0 Then
  
        NewRange.Copy Destination:=Worksheets("Test").Range("A3")
  
    End If
  
  End Sub
  </code></pre>
  
  <p>Thanks</p>