title: Excel VBA: how to solve Index and Match function type mismatch error
body: <p>I encounter error in index and match functions when the counter of date changes. I wrote a comment when I face with error. I uploaded a sample of my data if it needed. 
  sample : <a href="http://s000.tinyupload.com/?file_id=00243748825638974221" rel="nofollow">http://s000.tinyupload.com/?file_id=00243748825638974221</a></p>
  
  <p>here is the code :</p>
  
  <pre><code>Sub regionalAverage()
  
  Application.ScreenUpdating = False
  Application.DisplayStatusBar = False
  Application.EnableEvents = False
  ActiveSheet.DisplayPageBreaks = False
  
  ' *** change the declaration here ***
  Dim aname() As String
  Dim rw As Variant
  Dim col As Variant
  Dim date_ini As Date
  Dim date_fin As Date
  
  'create WorkSheet
  
  ' *** add Redim here, so the index of the array will start from 1 ***
  ReDim aname(1 To 2)
  
  date_ini = #1/1/2008#
  date_fin = #1/2/2008#
  For j = 1 To 3
      For conteo = date_ini To date_fin
          For i = 1 To 2
              With Sheets(i)
                 With Application
  
                      col = .Match(j, Worksheets(i).Range("F2:F23393"), 0)
                      rw = .Match(CLng(conteo),     Worksheets(i).Range("D2:D23393"), 0)
                     'error appeas here
                      aname(i) = .Index(Worksheets(i).Range("H2:H23393"), col, rw)  
  
  
  
                 End With
  
  
              End With
          Next i
  
      '    computation
          area = 6.429571
          Sheets("Output").Activate
          Range("A1").Select
          ActiveCell.Offset(0, j).Select
          colname = Split(ActiveCell(1).address(1, 0), "$")(0)
          Columns("" &amp; colname &amp; ":" &amp; colname &amp; "").Select
          Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, _
           LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
           MatchCase:=False, SearchFormat:=False).Select
  
          ActiveCell.Value = "=(SUM(" &amp; aname(1) &amp; "," &amp; aname(2) &amp; "))/" &amp; area &amp;  ""
  
      Next conteo
  Next j
  
  End Sub
  </code></pre>
  
  <p>When the date changes to 1/2/2008 I face with error, how can I solve it ?!</p>
  
  <p>Thank you</p>