Note that there are some explanatory texts on larger screens.

plurals
  1. POFor...Next with expanding range in Excel
    primarykey
    data
    text
    <p>I have a range of formulae in cells D5:D103 of a report, which link to another sheet in the book. Columns A:C contain text results, Column D has $ amounts as the results. A4:D4 contains headings for the data, and A1:D3 is a general heading to describe the report. The location of the last row will change each month, could be >103, could be &lt;103.</p> <p>After every 16 rows of data I need to insert 3 rows by 4 columns pasted from a named range in the sheet, and insert a total of the 16 rows in column D of the 2nd of the 3 rows. I then add a page break below ( a crude pagination exercise dictated by other requirements).</p> <p>The following code achieves most of this:-</p> <pre><code>Dim Formula1 As String Formula1 = "=SUM(R[-17]C:R[-2]C)" For i = 21 To (Range("a5", Range("d4").End(xlDown)).Rows.Count + 4) Step 19 Range("Total_credit").Select Selection.Copy Range("a" &amp; i).Select Selection.Insert Shift:=xlDown Range("a" &amp; i).Offset(1, 3) = Formula1 Selection.Offset(3).PageBreak = xlPageBreakManual Next i </code></pre> <p>However, I am left with a block of 19 rows of data at the bottom, which should be 2 blocks of 16 with the pasted text and a total below each (ideally there would be no blank rows in the last sequence, but I can live with that if I can get the rest right). The same issue seems to occur when I make the block of data a few rows bigger i.e. the last total will always be in the same place (D117).</p> <p>It appears the value of i is incrementing each loop, but this doesn't seem to be reflected in the process. I've tried all sorts of things and searched thoroughly to no avail, and my head is just spinning now. I'm sure someone will see instantly where I've gone wrong, it seems like it should be a simple fix.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload