ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   insert blank row (https://www.excelbanter.com/excel-programming/430429-insert-blank-row.html)

J.W. Aldridge

insert blank row
 
Want to insert blank row right before the first instance where a row
color is gray (color index 41).

Tried to work out the folliowing but no success.

Sub InsertRows()
Dim i As Long
i = 2
Do Until Trim(Cells(i, 1)) = ""
If cell.Interior.ColorIndex = 41 Then
Cells(i, 1).EntireRow.Insert
i = i + 2
Else
i = i + 1
End If
End Sub

Talorthain

insert blank row
 
On Jun 27, 11:08*am, "J.W. Aldridge"
wrote:
Want to insert blank row right before the first instance where a row
color is gray (color index 41).

Tried to work out the folliowing but no success.

Sub InsertRows()
Dim i As Long
i = 2
Do Until Trim(Cells(i, 1)) = ""
If cell.Interior.ColorIndex = 41 Then
Cells(i, 1).EntireRow.Insert
i = i + 2
Else
i = i + 1
End If
End Sub


try replacing cells(i,1).entirerow with

Rows(i:i).Select
Selection.Insert Shift:=xlDown


Regards

J.W. Aldridge

insert blank row
 

invalid post....

Wouldn't take "Rows(i:i).Select"


Per Jessen[_2_]

insert blank row
 
Try this:

Sub InsertRows()
Dim i As Long
i = 2
Do Until Trim(Cells(i, 1)) = ""
If Cells(i, 1).Interior.ColorIndex = 41 Then
Cells(i, 1).EntireRow.Insert
i = i + 2
Else
i = i + 1
End If
Loop
End Sub

Regards,
Per


On 27 Jun., 12:39, "J.W. Aldridge"
wrote:
invalid post....

Wouldn't take "Rows(i:i).Select"



J.W. Aldridge

insert blank row
 
thanx but didnt quite work.

Was my starting code not good?

Per Jessen[_2_]

insert blank row
 
You need a Loop statement to finish the Do / Loop loop, and in the
line:

If cell.Interior.ColorIndex .....

you have not Set any reference to the cell variable.

Best regards,
Per


On 27 Jun., 13:23, "J.W. Aldridge"
wrote:
thanx but didnt quite work.

Was my starting code not good?



J.W. Aldridge

insert blank row
 
i give up.

trying another route.

thanx!


All times are GMT +1. The time now is 12:32 AM.

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