title: Getting specific dates from a date range in VBA
body: <p>I have a sheet that have a range of dates in column A. I already found the way to get the last row with:</p>
  <pre><code>LastRow = Worksheets(&quot;TIME&quot;).Cells(Rows.Count, &quot;A&quot;).End(xlUp).Row
  </code></pre>
  <p>Now I am trying to get specific dates. The range contains no weekends, but since the dates are proprietary, I could not use the WorkDay function to find what I need.</p>
  <h2>Case 1:</h2>
  <p>From the last date available, I am trying to get the date 1 year before (if the date is not available, pick the next available one).</p>
  <p>What I did here was to use the date function and subtract 1 year..</p>
  <pre><code>day1Y = date(year(LastRow)-1,month(LastRow),day(LastRow))
  </code></pre>
  <p>To match, I transformed the date range into an array, and used a function do determine if it is in the array. If it is, get it, but if it is not, I don't know how to get the next available.</p>
  <pre><code>Dim DateArray() as Variant
  Dim WantedDate1 as date
  Dim WantedDate2 as date
  DateArray() = Worksheets(&quot;TIME&quot;).Range(&quot;A2:A&quot; &amp; LastRow).Value
  
  If IsInArray(day1Y) = True then
  WantedDate1 = .Cells(1,LastRow).Value
  End if
  </code></pre>
  <h2>Case 2:</h2>
  <p>From the last available date, I am trying to get the first date in the same year (if last date is 10/08/2015, it gets the first available date of 2015, according to the dates available in the range).</p>
  <pre><code>WantedDate2 = Year(.Cells(1,LastRow).Value)
  </code></pre>
  <p>I got the year of the last date, but again, I can't find the first date of that year.</p>
  <p>Any help will be deeply appreciated.</p>