title: VBA code to count distinct values based on multiple criteria
body: <p>I have a data sheet "orders" which has data in the format </p>
  
  <pre><code>order no    Customer    Sales Executive Order Status    Order Date
  211 nokia   john    cancelled   23-May-13
  643 panasonic   andrew  fulfilled   23-May-13
  209 samsung john    fulfilled   4-Apr-14
  453 philips andrew  fulfilled   4-Apr-14
  311 dell    mary    fulfilled   16-Apr-14
  865 panasonic   andrew  fulfilled   16-Apr-14
  201 apple   john    fulfilled   3-May-14
  453 hp  mary    cancelled   3-May-14
  205 nokia   john    fulfilled   4-May-14
  643 philips andrew  fulfilled   4-May-14
  312 lenovo  mary    fulfilled   22-May-14
  204 apple   john    fulfilled   7-Jun-14
  432 hp  mary    fulfilled   7-Jun-14
  214 nokia   john    pending 25-Jun-14
  754 panasonic   andrew  fulfilled   25-Jun-14
  </code></pre>
  
  <p>Above are the columns that matter out of the many columns in the order sheet.</p>
  
  <p>I have another worksheet where I have the "Sales Executives" listed and want to know how many unique customers they had orders fulfilled by month</p>
  
  <pre><code>Sales Executive Apr-14  May-14  Jun-14
  john    &lt;value&gt; &lt;value&gt; &lt;value&gt;
  mary    &lt;value&gt; &lt;value&gt; &lt;value&gt;
  andrew  &lt;value&gt; &lt;value&gt; &lt;value&gt;
  </code></pre>
  
  <p>I want to code to read the sales executive name in the row and month in the column and then give the answer like below</p>
  
  <pre><code>Sales Executive Apr-14  May-14  Jun-14
  john    1   2   1
  andrew  2   2   1
  mary    1   1   1
  </code></pre>
  
  <p>I am looking for a vba code that can run this on a monthly basis. The above example is a sample set of the actual data.</p>
  
  <p>I am relatively new to VBA and need help with the code. </p>
  
  <p>It would be helpful if I get an explanation on the code as how it work as I need similar code to find how many products and total revenue generated by each sales executive for the months.</p>
  
  <p>Thanks for your help in advance</p>
  
  <p><strong>EDIT</strong> (code from OP comment below):</p>
  
  <pre><code>Sub UniqueReport() 
  Dim dict As Object 
  Set dict = CreateObject("scripting.dictionary") 
  Dim varray As Variant, element As Variant 
  Dim lastrow As Long 
  
  lastrow = Sheets("Orders").Range("N" &amp; Rows.Count).End(xlUp).Row varray = Sheets("Orders").Range("N2:N" &amp; lastrow).Value 
  
  For Each element In varray 
      If dict.exists(element) Then 
          dict.Item(element) = dict.Item(element) + 1 
      Else 
          dict.Add element, 1 
      End If 
  Next 
  
  ActiveSheet.Range("P2").Value = dict.Count 
  End Sub 
  </code></pre>