Add new rows using reference cell

crabab11

New Member
Joined
Mar 13, 2014
Messages
2
I have a spreadsheet with several hundred files, each has n number of images in it. What I need to do is insert a row for every image, below the original file. So I put the number of rows to insert into the main row, and would like to use that as the reference value.
Like this:

image names

<tbody>
</tbody>
# images

<tbody>
</tbody>
IE

<tbody>
</tbody>
Representation

<tbody>
</tbody>
File

<tbody>
</tbody>
H002.tif

<tbody>
</tbody>
10

<tbody>
</tbody>
IE

<tbody>
</tbody>
Representation

<tbody>
</tbody>
File
H003.tif

<tbody>
</tbody>
3

<tbody>
</tbody>

<tbody>
</tbody>


I found someone else had something like this but I think it's meant for rows that are one after the other, not with the two empty rows in-between. It will insert the first set of rows but then doesn't continue for the next value. Also, I think it's set up to include the existing row in the count. So, would it be possible to set it to insert 10 rows, then skip 2, read the next value, etc.?

The code I found:

Code:
[COLOR=#333333]Sub AddColumns()[/COLOR]
[COLOR=#333333]Dim i As Integer, n As Integer, m As Long, currentCell As Range[/COLOR]
[COLOR=#333333]Set currentCell = ActiveCell[/COLOR]
[COLOR=#333333]Do While Not IsEmpty(currentCell)[/COLOR]
[COLOR=#333333]n = currentCell.Value - 1[/COLOR]
[COLOR=#333333]m = currentCell.Row[/COLOR]
[COLOR=#333333]If n > 0 Then[/COLOR]
[COLOR=#333333]Rows(m + 1 & ":" & m + n).Insert[/COLOR]
[COLOR=#333333]Set currentCell = currentCell.Offset(n + 1, 0)[/COLOR]
[COLOR=#333333]Else[/COLOR]
[COLOR=#333333]Set currentCell = currentCell.Offset(1, 0)[/COLOR]
[COLOR=#333333]End If[/COLOR]
[COLOR=#333333]Loop[/COLOR]
[COLOR=#333333]End Sub[/COLOR]

Hopefully I explained this well, sorry it's so much.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,214,376
Messages
6,119,180
Members
448,871
Latest member
hengshankouniuniu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top