ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Please help... (https://www.excelbanter.com/excel-programming/403566-please-help.html)

[email protected]

Please help...
 
I have a problem. How to insert a row below a cell that contains a
given sign? For example, I need to insert a new row below every cell
that contains x? X is in in every row in column A.

Ian[_4_]

Please help...
 
Assumes your data starts at row 1.
Change the limits of r to suit your requirement. Note that, as the code adds
a blank line after each X, this row range will have to be at least double
the original row range.
Note that X is case specific.

Sub test()
' Lower value for r should be first data row + 1
' Upper value = lower value + number of original rows
For r = 2 To 20
' X is case specific
If Cells(r - 1, 1).Value = "X" Then
Cells(r, 1).EntireRow.Insert
End If
Next
End Sub

Ian
wrote in message
...
I have a problem. How to insert a row below a cell that contains a
given sign? For example, I need to insert a new row below every cell
that contains x? X is in in every row in column A.




excelent

Please help...
 
Sub insetRows()

Set sh = Sheets("Sheet1")
rw = sh.Cells(65500, 1).End(xlUp).Row

For c = rw To 1 Step -1
If sh.Cells(c, 1) = "X" Then sh.Cells(c, 1).EntireRow.Insert
Next

End Sub


" skrev:

I have a problem. How to insert a row below a cell that contains a
given sign? For example, I need to insert a new row below every cell
that contains x? X is in in every row in column A.


JLGWhiz

Please help...
 
To avoid errors if case sensitive:

Sub rwInsrt()
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2 Step -1
If LCase(Cells(i, 1)) = "x" Then
Cells(i, 1).EntireRow.Insert
End If
Next
End Sub


" wrote:

I have a problem. How to insert a row below a cell that contains a
given sign? For example, I need to insert a new row below every cell
that contains x? X is in in every row in column A.


Dan R.

Please help...
 
I think he meant:

Cells(i + 1, 1).EntireRow.Insert

--
Dan

On Jan 3, 7:46*am, wrote:
I have a problem. How to insert a row below a cell that contains a
given sign? For example, I need to insert a new row below every cell
that contains x? X is in in every row in column A.



All times are GMT +1. The time now is 10:14 AM.

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