ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inserting # of rows depending on value in Column (https://www.excelbanter.com/excel-programming/281761-inserting-rows-depending-value-column.html)

Christel

Inserting # of rows depending on value in Column
 
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!

Tom Ogilvy

Inserting # of rows depending on value in Column
 
Assume the cell with xyz is selected

x = 3
ActiveCell.offset(1,0).Resize(x,1).EntireRow.Inser t

--
Regards,
Tom Ogilvy

Christel wrote in message
...
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!




No Name

Inserting # of rows depending on value in Column
 
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


-----Original Message-----
Assume the cell with xyz is selected

x = 3
ActiveCell.offset(1,0).Resize(x,1).EntireRow.Inse rt

--
Regards,
Tom Ogilvy

Christel wrote in

message
...
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!



.


No Name

Inserting # of rows depending on value in Column
 
I should also mention that Column 11 is a formula that
calculates a number

-----Original Message-----
Assume the cell with xyz is selected

x = 3
ActiveCell.offset(1,0).Resize(x,1).EntireRow.Inse rt

--
Regards,
Tom Ogilvy

Christel wrote in

message
...
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!



.


Dianne

Inserting # of rows depending on value in Column
 
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

--
HTH,
Dianne
In ,

typed:
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


-----Original Message-----
Assume the cell with xyz is selected

x = 3
ActiveCell.offset(1,0).Resize(x,1).EntireRow.Inser t

--
Regards,
Tom Ogilvy

Christel wrote in message
...
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!



.




No Name

Inserting # of rows depending on value in Column
 

Thank you so much! that did the trick!


All times are GMT +1. The time now is 03:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com