title: VBA WorksheetFunction dynamic randbetween
body: <p>hope all is well.</p>
  
  <p>I am slightly stuck on a VBA function called randbetween in Excel.</p>
  
  <p>Nature of the problem is that I need to create random numbers based on a bunch of other numbers, about 50,000 other numbers in total.</p>
  
  <p>The random numbers I generate must be between 1 and X. X being the other numbers in column D1:D50,000.</p>
  
  <p>As an example: if cell D1 contains the number 5, then I need to create a random number between 1 and 5 in Cell A1. then move on to D2,D3,D4.....etc and create random numbers for each one accordingly, A2,A3,A4...etc.</p>
  
  <p>I tried to use the following but unfortunately the offset part doesn't work. I want to dynamically work through each cell.</p>
  
  <p>the code is as follows:</p>
  
  <pre><code>r = WorksheetFunction.RandBetween(1, Offset(A1, n, 9))
  'where n = 2
  </code></pre>
  
  <p>Most grateful for any help,</p>