title: Copy all rows between two time values
body: <p>I have a table with about 6000 rows and in column Z there is a date and time value. The formatting looks like this:</p>
  
  <pre><code>2020-01-29  13:18:36
  </code></pre>
  
  <p>I want to copy and paste all the row between Now and 30 minutes back. For example if the current time is 08:00 I want to copy all the rows from "2020-01-30  07:30:00" to "2020-01-30  08:00:00".</p>
  
  <p>Something like this is what I have in mind:</p>
  
  <pre><code>.AutoFilter Field:=26, Criteria1:="&lt;=Now", Operator:=xlAnd, Criteria2:="&gt;=Now-30 minutes"
  .SpecialCells(xlCellTypeVisible).Copy Destination:=Sheet2.Range("A1")
  </code></pre>
  
  <p>How do I get the current time formatted like the example above and the time 30 minutes back and how do I insert it in to AutoFilter?</p>
  
  <p>Thanks in advance!</p>
  
  <p>/Jens</p>
  
  <p>Edit:</p>
  
  <p>This code works:</p>
  
  <pre><code>Dim LastRow
  LastRow = Sheets("privata").Range("A" &amp; Rows.Count).End(xlUp).Row
  
  Sheets("privata").Range("A1:AN" &amp; LastRow).AutoFilter Field:=26, Criteria1:="&gt;=2020-01-30  08:00", Operator:=xlAnd, Criteria2:="&lt;=2020-01-30  08:30"
  Sheets("privata").Range("A1:AN" &amp; LastRow).SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("toptre").Range("A1")
  Sheets("privata").ShowAllData
  </code></pre>
  
  <p>But this doesn't:</p>
  
  <pre><code>Dim Nu As Date
  Dim PreNu As Date
  Dim LastRow
  Nu = Now
  PreNu = Now - 1 / 48
  LastRow = Sheets("privata").Range("A" &amp; Rows.Count).End(xlUp).Row
  
  Sheets("privata").Range("A1:AN" &amp; LastRow).AutoFilter Field:=26, Criteria1:="&lt;=" &amp; Nu, Operator:=xlAnd, Criteria2:="&gt;=" &amp; PreNu
  Sheets("privata").Range("A1:AN" &amp; LastRow).SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("toptre").Range("A1")
  Sheets("privata").ShowAllData
  </code></pre>
  
  <p>Here's an example of the table:
  <a href="https://i.stack.imgur.com/vzL2X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vzL2X.png" alt="enter image description here"></a></p>