Inserting # of rows depending on value in Column

C

Christel

I have a spreadsheet where I need to insert x number of
rows below the row where the column = "x" For ex.

A B C D
abc 123 xyz 3 I need excel to insert 3 rows beneath
this row.

Any help is appreciated, because I'm not having much luck!

Thanks!
 
T

Tom Ogilvy

Assume the cell with xyz is selected

x = 3
ActiveCell.offset(1,0).Resize(x,1).EntireRow.Insert
 
G

Guest

Sorry, I should have been more specific. I need to go
through rows 2 to 1000, checking each column 11 for the
value that I need to insert that number of rows under.
I have this and it "kind of" works, but it inserts the
rows in the wrong place. Any more suggestions? Thanks!

Sub addrows()
Dim intCol As Integer
Dim intRow As Integer
For intRow = 3 To 1000
intCol = 11
If Worksheets("Master Schedule").Cells(intRow,
intCol).Value <> "" Then
Rowinsert = Value
ActiveCell.Offset(1, 0).EntireRow.Insert
intRow = intRow + 1
 
D

Dianne

Building on Tom's answer and your own macro... try:

Sub AddRows()
Dim intRow As Integer
Dim strValue As String
Dim intNumRows As Integer
Dim rng As Range

For intRow = 3 To 1000
Set rng = Worksheets("Master Schedule").Cells(intRow, 11)
strValue = rng.Value
If strValue <> "" And IsNumeric(strValue) Then
intNumRows = CInt(strValue)
rng.Offset(1, 0).Resize(intNumRows, 1).EntireRow.Insert
End If
Next intRow

End Sub

Please note that when you use the for/next statement, you don't need to
increment your counter -- ie you don't need to do intRow = intRow + 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top