I am fairly new to VBA. In the below code, I am attempting to search the list of numbers in the array in a dynamic column. If the number is found, then a new line is inserted. However, I get an error when the number in the array is not found. If there is a more efficient way to do the same thing, I would be happy to change the code. Any help is greatly appreciated.
Sub InsertLines()
Dim vBUsort As Variant
Dim vSheet As Worksheet
Dim i As Integer
vBUsort = Array("3", "4", "5", "6", "7", "8", "9", "10")
For Each vSheet In ThisWorkbook.Worksheets
Range("A1").Select
Application.ActiveSheet.Range("1:2").Find(What:="BU Sort Priority", _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False).Select
With ActiveCell.EntireColumn.Select
For i = LBound(vBUsort) To UBound(vBUsort)
Selection.Find(What:=vBUsort(i), After:=ActiveCell, _
LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.EntireRow.Insert
ActiveCell.EntireRow.Interior.Color = 6697728
Next i
End With
Next vSheet
End Sub