title: Date Type Mysmatch in a Counter
body: <p>I am designing a Pre sequencing VBA code that must seek the value introduced in a row (In this case the row Z starting in Z4 and ending in Z15) and must verify if it already exists in another row (in this case the row AC starting in AC4 and ending in AC15). If it does not exist it must place the time in the corresponding cell of the row AC (e.g. Z4 --> AC4, Z5 --> AC5). This is a way in which I assure that no AC cell contains a value equal to another AC value (understand the AC values as places in a row with two minutes of difference). If it finds the value of the Z row in the AC row, it must add two minutes to the Z value and check again if that "place" is already taken, until it founds a free place.</p>
  
  <p>In the code below you can see the example for the cell Z4, that will be a repititive statement for each Z in the row.</p>
  
  <p>It runs the counter Nº4 perfectly, but as soon as it gives the counter Nº5, in the line 'ActualHour=CDate(Worksheets("Hoja1").Cells(Counter, 29))' It brings the ‘Run-time error ‘13’: Type mismatch’. I do not know why because the type is still the same, and the values too, I attach images of the counter 4 and 5: <a href="https://i.stack.imgur.com/MzqRM.png" rel="nofollow noreferrer">Counter4</a> <a href="https://i.stack.imgur.com/SVxu0.png" rel="nofollow noreferrer">Counter5</a></p>
  
  <pre><code>Sub TSAT4()
      Dim DesiredHour As Date
      Dim HourTaken As Boolean
      Dim ActualHour As Date
      HourTaken = True
      DesiredHour = CDate(Range("Z4"))
      Do While HourTaken = True
          HourTaken = False
          For Counter = 4 To 15
              ActualHour = CDate(Worksheets("Hoja1").Cells(Counter, 29))
                  If CDate(ActualHour) = DesiredHour Then DesiredHour = DateAdd("n", 2, DesiredHour) And HourTaken = True
              Next Counter
      Loop
  Sheets("Hoja1").Range("AC4") = DesiredHour
  Application.CutCopyMode = False
  End Sub
  </code></pre>