add some text in a cell that has just been inserted

J

Janis

When you use these lines of code in a for loop

Set rng = .Cells(iRow, ServiceGroupColumn)

rng.Offset(SvcGrpNum / 2, 0).Resize(rowsToAdd + 1).EntireRow

What would be the way to add some text in the irow cell for all those
inserted rows.

tia,
 
D

Dave Peterson

I'm not sure what you mean by the irow cell.

You sure you didn't mean that you want to populate servicegroupcolumn in each of
the inserted rows?

If yes, this worked ok for me:

Option Explicit
Sub testme()

Dim Rng As Range
Dim iRow As Long
Dim ServiceGroupColumn As Long
Dim SvcGrpNum As Long
Dim RowsToAdd As Long

ServiceGroupColumn = 3
iRow = 4
SvcGrpNum = 4
RowsToAdd = 17

With Worksheets("Sheet1")
Set Rng = .Cells(iRow, ServiceGroupColumn)
End With

Rng.Offset(SvcGrpNum / 2, 0).Resize(RowsToAdd + 1).EntireRow.Insert
Rng.Offset(SvcGrpNum / 2, 0).Resize(RowsToAdd + 1).Value = "hi there"

End Sub
 

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