title: VBA Excel - Run-time Error 13 Type Mismatch when using WorksheetFunction.SumIF
body: <p>I have two Sheets of data. One <code>Sheets("Expenses")</code> is populated with all of my bills and what account they are associated to in the Rows and all of the Columns are a consecutive list of dates. The cells beneath the dates are only filled if the Expense for that particular Row is due on that Date.</p>
  
  <p>In the second <code>Sheets("Totals")</code>, I have each Account listed in the Rows and the Dates consecutively listed in the Columns much like the <code>Sheets("Expenses")</code>. What I want to do is to use <code>WorksheetFunction.SumIf</code> is to populate the cells on `Sheets("Totals") with the total amounts of each Account on each Date.</p>
  
  <p>There is a little bit of redundant code in what I have below but that's just because I haven't got this working yet or optimised.</p>
  
  <p>The Problem that I am getting is a Run-Time Error 13: Type Mismatch on the line <code>accSum = WorksheetFunction.SumIf(objSum, objExpAcc, strAccount)</code>. I thought that I followed the MSDN examples properly but for some reason I can't get it to work.</p>
  
  <p>I don't know if it makes any difference but on <code>Sheets("Expenses")</code> the first two <code>Rows</code> are header rows that contain a mixture of Dates and Strings.</p>
  
  <pre><code>Public Sub upAccRows()
  Dim startDate As Date
  Dim endDate As Date
  Dim dExp As Integer
  Dim stDateCol As Integer
  Dim lDateCol As Integer
  Dim lExp As Integer
  Dim strAccount As String
  Dim lRow As Integer
  Dim currentDate As Date
  Dim objSum As Range
  Dim objExpAcc As Range
  Dim accSum As Integer
  Dim strTest As String
  
  startDate = Worksheets("Summary").Range("B2").Value
  endDate = Worksheets("Summary").Range("B1").Value
  lRow = Worksheets("Expenses").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row 'Last row of entries
  
  With Sheets("Totals")
      startExp = .Cells.Find("Expenses", SearchOrder:=xlByRows, SearchDirection:=xlNext).Row + 1
      startInc = .Cells.Find("Income", SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
      stDateCol = .Cells.Find(What:=startDate, SearchOrder:=xlByColumns, SearchDirection:=xlNext).Column
      lDateCol = .Cells.Find(What:=endDate, SearchOrder:=xlByColumns, SearchDirection:=xlNext).Column
      lExp = startInc - 1
  End With
  '~~&gt; Loops through the rows of the Accounts on the Accounts Sheet
  For CountA = startExp To lExp
      '~~&gt; Loops through the columns of the Dates on the Accounts Sheet
      For CountB = stDateCol To lDateCol
          '~~&gt; Set Variables for the SumIf Function and Do
          With Sheets("Totals")
              currentDate = .Cells(1, CountB).Value
              strAccount = .Cells(CountA, 2).Value
          End With
          With Sheets("Expenses")
              dExp = .Cells.Find(What:=currentDate, SearchOrder:=xlByColumns, SearchDirection:=xlNext).Column
              Set objSum = .Columns(dExp)
              Set objExpAcc = .Columns(3)
              accSum = WorksheetFunction.SumIf(objSum, objExpAcc, strAccount)
              MsgBox "accSum = " &amp; accSum
          End With
          'Sheets("Totals").Cells(CountA, CountB).Value = accSum
          dExp = dExp + 1
      Next CountB
  Next CountA
  
  End Sub
  </code></pre>