title: How can I make a cell reference a function of a variable?
body: <p>I will be using the same macro 24 times, but the ranges will differ (but at a constant rate) every time. Therefore I thought it would be smart to write the references as a function in order to reduce the length of the code, and also make it easier to change.</p>
  <p>Now it looks like this:</p>
  <pre><code>    Sheets(&quot;Planned time&quot;).Select
      Range(&quot;I15:NJ32&quot;).Select
      Selection.Copy
      Sheets(&quot;Diff&quot;).Select
      Range(&quot;I9&quot;).Select
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
          :=False, Transpose:=False
  </code></pre>
  <p>But I would like it to be something like this:</p>
  <pre><code>    Sheets(&quot;Planned time&quot;).Select
      Range(&quot;I(15+171x):NJ(32+171x)&quot;).Select
      Selection.Copy
      Sheets(&quot;Diff&quot;).Select
      Range(&quot;I(9+56x)&quot;).Select
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
          :=False, Transpose:=False
  </code></pre>
  <p>Where the macro loops 24 times, but for each loop, increase the value of x by 1. x would need to be 0 in the first iteration, and 23 in the last one (totalling 24 iterations).</p>
  <p>I know the coding is probably far off, but I think it illustrates what I want to accomplish in a good way.</p>
  <p>Any assistance would be greatly appreciated.</p>
  <p>UPDATE:
  Solved</p>
  <pre><code>Dim x As Integer
  
  For x = 0 To 23
  
  Sheets(&quot;Planned time&quot;).Select
  
  Range(&quot;I&quot; &amp; cstr(15+171*x) &amp; &quot;:NJ&quot; &amp; cstr(32+171*x)).Select
  
  Selection.Copy
  
  Sheets(&quot;Diff&quot;).Select
  
  Range(&quot;I&quot; &amp; cstr(9+56*x)).Select
  
  Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  
  :=False, Transpose:=False
  
  Next x
  </code></pre>