excelvbaexcel-tableslistobject

How to insert 15 blank rows every time a cell begins with "SB"


How can I add 15 rows when my column H begins with 'SB' please?

This is a snippet of the data I have: enter image description here

I need to insert 15 rows under each occurrence of a cell beginning with 'SB' in column H[Data.SOURCE]. Here are some examples highlighted, of when names begin with 'SB': enter image description here

So it would begin to look like this: enter image description here

I have tried lots of googling and this stack page, but it hasn't worked: How to insert a blank row based on cell value

Any help would be appreciated. Thank you!


Solution

  • Dim cRows as Long, i as long,j as Long
    cRows=ActiveSheet.UsedRange.Rows.count
    For i=cRows to 1 step-1
    If Left(Cells(i,8),2)="SB" Then 
    For j=1 to 15
    Rows(i+1).EntireRow.Insert
    next j
    End If
    Next i
    

    Something like that