Please, also test the next way. It places the range to be processed in an array (for faster processing) and creates a Union
range of the necessary rows to be inserted. It makes insertion at the end, at once, being fast for a reasonable number of occurrences:
Sub insertRows(rng As Range, pref As String, noRows As Long)
Dim URng As Range, arr, i As Long
arr = rng.Value2
For i = 1 To UBound(arr)
If left(arr(i, 1), Len(pref)) = pref Then
addToRange URng, rng.Parent.Range(i + rng.row & ":" & i + rng.row + noRows - 1)
End If
Next i
If Not URng Is Nothing Then URng.insert xlDown
End Sub
It should be called in the next way (for variable insertions number):
Sub testInsertRows()
Dim sh As Worksheet, lastR As Long, rng As Range
Set sh = ActiveSheet 'use here the sheet you need
lastR = sh.Range("H" & sh.rows.count).End(xlUp).row
Set rng = sh.Range("H2:H" & lastR)
insertRows rng, "SB", 3
End Sub
The necessary Sub
to create the Union
range (to be copied in a standard module, usually the one where the above code should also be):
Sub addToRange(rngU As Range, rng As Range)
If rngU Is Nothing Then
Set rngU = rng
Else
Set rngU = Union(rngU, rng)
End If
End Sub