title: Weighted average rate in VBA
body: <p>I am quite new to VBA so I am sorry if my question might seems very trivial.
  I would love to write a function in VBA which helps to estimate weighted average rate (for loan portfolio, for instance). I wrote the following VBA code:</p>
  
  <pre><code>Function WAIRS(Amount As Range, InterestRate As Range, MatchRange As Range, Match1)
  WAIRS = Evaluate("=SUMPRODUCT(--(""" &amp; MatchRange &amp; """ = """ &amp; Match1 &amp; """),""" &amp; Amount &amp; """, """ &amp; InterestRate &amp; """)")      /Application.WorksheetFunction.SumIfs(Amount, MatchRange, Match1)
  End Function
  </code></pre>
  
  <p>The problem is that when I run this function in Excel by adding respective function criterias I get an "#VALUE#". I have tried a lot but cannot find out what is wrong. I Would highly appreciate if you can help me.</p>
  
  <p>Thank you in advance.</p>
  
  <p>Best,
  Jeyhun</p>