title: Using VBA to search and match two parameters to pull a value
body: <p>I am doing a project that requires searching through a very large list of sales, meaning that it is a large dataset and time is something we are trying cut down on. The dataset essentially contains three pieces of information: The type of object purchased, the date is was purchased, and the amount. For simplification, I'm going to dumb down the examples below.</p>
  
  <p>In addition to this dataset, we have a tab created for each of the types of objects with each date of the year running down the left hand side. The end goal of the project is to populate the purchase information onto each of these tabs so that we can do further, non-excel based, analysis.</p>
  
  <p>The purchases look like the following. In real data, there are thousands of lines of purchase and a dozen or so types (Contained in a table called "Purchases").</p>
  
  <pre><code>Product_Type         Purchase_Date         Amount
  ------------         -------------         ------
  Prod A               1/1/2016              15
  Prod A               1/3/2016              10
  Prod A               1/8/2016              5
  Prod A               1/10/2016             15
  Prod A               1/15/2016             25
  Prod B               1/5/2016              25
  Prod B               1/7/2016              25
  Prod B               1/10/2016             25
  Prod B               1/13/2016             25
  </code></pre>
  
  <p>The resultant tab will look as follows:</p>
  
  <pre><code>Product Type: Prod A      (In it's own hard-coded cell, let's say A1)
  Date          Purchases
  1/1/2016      15
  1/2/2016      0
  1/3/2016      10
  1/4/2016      0
  1/5/2016      0
  1/6/2016      0
  1/7/2016      0
  1/8/2016      5
  ... (fills out entire year)
  </code></pre>
  
  <p>The number in the purchase column is what we WANT to go there. The dates are also being populated when the tabs are created, so we can't necessarily use a SUMIF hardcoded in there.</p>
  
  <p>Currently, we are doing it in a very roundabout way that takes a long time: This is contained within a much larger script and it does this for each tab.</p>
  
  <pre><code>Set InfoDataRange = Range("Purchases[Product_Type]:Purchases[Amount]")
  FirstDate = DateAdd("yyyy", -1, Sheets("Control Log").Range("D6").Value) --populates 1/1
  LastDate = Sheets("Control Log").Range("D6").Value -- populates 12/31
      Rownum = 2
      Do
          FirstDate = FirstDate + 1
          Cells(Rownum, 1) = FirstDate
          For Each InfoDataRow In InfoDataRange
              If InfoDataRow.Cells(1, 1) = Range("A1") And _  'Matching product
                 InfoDataRow.Cells(1, 2) = FirstDate Then     'Matching date
              Cells(Rownum, 2) = InfoDataRow.Cells(1, 3)
              End If
          Next
          Rownum = Rownum + 1
      Loop Until FirstDate = LastDate
  </code></pre>
  
  <p>I'm not necessarily looking for someone to do it for me, but am very open to any ideas to make the search go much faster.</p>
  
  <p>Thanks!</p>