title: Output populated in next row and not overwrite existing row in VBA loop procedure
body: <p>I have the following loop within my Excel VBA code:</p>
  <pre><code> 'Loop through all tickers
      For ticker = firstTickerRow To lastRow
  
          tickerSymbol = Worksheets(&quot;Port&quot;).Range(&quot;$a$&quot; &amp; ticker)
  
          If tickerSymbol = &quot;&quot; Then
              GoTo NextIteration
          End If
  
      'Get financial data from Yahoo and write into each sheet
      'getCookieCrumb() must be run before running getYahooFinanceData()
      '***************************************************
      Call getYahooFinanceData(tickerSymbol, startDate, endDate, frequency, cookie, crumb)
      '***************************************************
  
  NextIteration:
      Next ticker
  </code></pre>
  <p>The output shows up as a single row, i.e. the data is overwritten over the loop and only populates that single row. However, my intended output is shown in the second table whereby the data populates the next row with no overwriting.</p>
  <p>The error is within the subprocedure <code>getYahooFinanceData()</code>, which contains the following output code:</p>
  <pre><code>'Write results into worksheet for ticker
  Worksheets(&quot;Port&quot;).Range(&quot;$B$4&quot;).Resize(UBound(resultArray, 1) + 1, UBound(resultArray, 2) + 1).Value = resultArray
  </code></pre>
  <p>I tried replacing <code>.Range(&quot;$B$4&quot;)</code> with <code>.Range(&quot;$B$&quot; &amp; ticker)</code> to make the output location dynamic but this does not work. There is run-time error '1004', probably because <code>ticker</code> is not found within the sub-procedure <code>getYahooFinanceData()</code></p>
  <p>How can I amend my code to ensure that the correct output with no overwriting is produced?</p>
  <p>Current output with overwritten data</p>
  <pre><code>+--------+----------+-------------+--------+-------------+-------------+-------------+---------+
  | Ticker |   Date   |    Open     |  High  |     Low     |    Close    |  Adj Close  | Volume  |
  +--------+----------+-------------+--------+-------------+-------------+-------------+---------+
  | MSFT   | 4-Feb-20 | 1457.069946 | 1469.5 | 1426.300049 | 1447.069946 | 1447.069946 | 3933000 |
  | GOOG   |          |             |        |             |             |             |         |
  +--------+----------+-------------+--------+-------------+-------------+-------------+---------+
  </code></pre>
  <p>Intended output</p>
  <pre><code>+--------+----------+-------------+------------+-------------+-------------+-------------+----------+
  | Ticker |   Date   |    Open     |    High    |     Low     |    Close    |  Adj Close  |  Volume  |
  +--------+----------+-------------+------------+-------------+-------------+-------------+----------+
  | MSFT   | 4-Feb-20 |  177.139999 | 180.639999 |  176.309998 |  180.119995 |  178.231873 | 36433300 |
  | GOOG   | 4-Feb-20 | 1457.069946 |     1469.5 | 1426.300049 | 1447.069946 | 1447.069946 |  3933000 |
  +--------+----------+-------------+------------+-------------+-------------+-------------+----------+
  </code></pre>