#### Alastair 1210

##### New Member

- Joined
- Nov 8, 2014

- Messages
- 3

I need some vba code to allow the contents of a row to be copied and inserted into the row below, X-1 times, depending on the X value in a cell.

I've designed a spreadsheet for a friend allowing him to analyse his sheep flock. The information relating to each specific ewe occupies an individual row. There are 150 ewes in his flock - 150 rows from A5 through to A155. Each ewe is identified by a unique code e.g. 1000, 1001, 1002 and recorded in rows B5 to B155.

Each ewe will produce 1, 2, or 3 lambs. Each lamb produced is also given a unique code, recorded in the same row as the ewe that gave birth to it - column C. Each lamb code is therefore linked to the ewe code and both ewe codes and lamb codes can be sorted sequentially.

I need to be able to enter a 1, 2 or 3 into cells A5 through to A155 thereby identifying how many lambs a particular ewe has given birth to.

If a 1 is entered in cell A5, i.e. a particular ewe ‘1000’ has 1 lamb, nothing needs to happen - the unique lamb code ’L1000’ is entered in C5.

If a 2 is entered in A5, i.e. ewe ‘1000’ has 2 lambs, row 5 should be copied and inserted below into row 6

*once (*All the remaining ewe codes shift down a row) so there will now be 2 rows for ewe code ‘1000’. The unique lamb codes ‘L1000’ and ‘L1001’ can be entered in cells C5 and C6.

If a 3 is entered in A5, i.e. ewe ‘1000’ has 3 lambs, row 5 should be copied and inserted below into rows 6 & 7

*(*All the remaining ewe codes shift down 2 rows) so there will now be 3 rows for ewe code ‘1000’. The unique lamb codes ‘L1000’, ‘L1001’ and ‘L1002’ can be entered in cells C5, C6 and C7.

I would be very grateful if someone could advise me on the vba code to enable me to do this saving much effort and time.

Many thanks

Alastair