I just figured out how to insert rows below cell with value. However as an addition I would like inserted row to be specific height, lets say for example 7. This code is a part of large code so I don't save sub
in my example.
The problem is that this code is not working for setting RowHeight. First part is is inserting new row but there is no effect on Height of the rows.
I have tried the following one:
Dim rng as Range
For Each Rng In ThisWorkbook.Worksheets("Offer Letter").Range("E2:E60")
If Not IsEmpty(Rng) Then
Rng.Offset(1, 0).EntireRow.Insert
End If
Next
For Each Rng In ThisWorkbook.Worksheets("Offer Letter").Range("E2:E60")
If Not IsEmpty(Rng) Then
Rng.Offset(1, 0).EntireRow.RowHeight = 7
End If
Next
You don't say what your problem is, but you don't need two loops. Set the height when you insert the row.
Thanks to @JvdV for pointing out that when deleting or inserting rows one should loop backwards to avoid missing/skipping rows.
Sub y()
Dim r As Long
With ThisWorkbook.Worksheets("Offer Letter")
For r = 60 To 2 Step -1
If Not IsEmpty(.Cells(r, "E")) Then
.Cells(r + 1, "E").EntireRow.Insert
.Cells(r + 1, "E").EntireRow.RowHeight = 7
End If
Next r
End With
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.