I have many rows in a document in which I need to insert a certain subset of rows with others. In particular, I need one row for each month considered. If I have the row starting with July and finishing with September, I need to replace that row with 3 rows, one for July, one for August and one for September.
How can I do it automatically?

Answer
I assume that your data look like this:

(1) I formatted columns E and F as mmm-yy (m/yyyy) to avoid language-based confusion.
(2) There is a copyable version of the above in this answer’s source.
on Sheet1, and that you want to copy it to Sheet2 with the extra rows added. You can do that with three “helper columns” on Sheet2 — in the below steps, I use X, Y, and Z. Here’s how to do it:
- Copy the column headings from
Sheet1, row 1, toSheet2, row 1. - Enter
=IF($Y2=0, INDEX(Sheet1!A:A, $X2), "")intoSheet2!A2and drag/fill to the right to cover all your data (i.e., to columnI). - Copy
Sheet1:A2:I2and paste formats ontoSheet2:A2:I2. - Change
Sheet2!E2(begin month) to
=DATE(YEAR(INDEX(Sheet1!E:E, X2)), MONTH(INDEX(Sheet1!E:E, X2))+Y2, 1). - Enter
2inSheet2!X2. This designates the row onSheet1that this row (onSheet2) will pull data from, so, for example, if your data actually begin in row 61 onSheet1, enter61inSheet2!X2. - Enter
0inSheet2!Y2. - Enter
=INDEX(Sheet1!F:F, $X2)intoSheet2!Z2. (If you want, format it as a date.) - Select
Sheet2!A2:Z2and drag/fill down to row 3. - Change
Sheet2!X3to=IF(E2. - Change
Sheet2!Y3to=IF(E2. - Select
Sheet2!A3:Z3and drag/fill down as far as you need to get all your data.
It should look something like this:
Notes:
- As stated in the instructions,
Sheet2!Xnspecifies the row onSheet1that rown(onSheet2) will pull data from. Sheet2!Ynis a one-up number within aSheet2!Xnvalue; i.e., within aSheet1row. For example, since rows 3-6 onSheet2pull data fromSheet1row 3, we haveX3=X4=X5=X6=3, andY3,Y4,Y5,Y6= 0, 1, 2, 3.- Column
Zis just the “true” branch of theIFexpression in columnF; i.e., the end month for this group of rows.
Of course you can hide columns X, Y, and Z. Or, if you want to do this just once and be done, you can copy and paste values.

No comments:
Post a Comment