I have encounter a situation, the codes that i have below sometime runs without any error message, but sometime it gives me a Run-Time Error '91': Object variable or With block variable not set
VBA Code:
Sub NFLH2H2()
Application.ScreenUpdating = False
''Total Receiving Yards by the Player
Const FindWhat As String = "Total Receiving Yards by the Player"
Dim mR As Long, Sr As Range, Sf As Range, gAdr As String, wA As Variant
Set Sr = Sheets("NFL H2H Paste Here").Range("A1:A20000")
Set Sf = Sr.Find(FindWhat, [A1], xlFormulas, xlPart, xlByRows, xlNext)
gAdr = Sf.Address
wA = Sf.Resize(8, 1).Value
Sheets("Total Receiving Yards").Range("A1").Resize(8, 1).Value = wA
Do
Set Sf = Sr.FindNext(Sf)
If Sf Is Nothing Then GoTo NextI
If Sf.Address = gAdr Then Exit Do
wA = Sf.Resize(8, 1).Value
With Sheets("Total Receiving Yards")
mR = .Range("A" & Rows.count).End(xlUp).Row + 1
.Range("A" & mR).Resize(8, 1).Value = wA
End With
Loop
Dim s As Integer, iRow As Integer
Dim arrSource As Variant
'Set the first row
sRow = 2
With ActiveWorkbook.Worksheets("Total Receiving Yards")
'get the data into an array from the first column
arrSource = Range(.Cells(1, 1), .Cells(.Rows.count, 1).End(xlUp))
'parse every value of the array and add the data to the next column
For s = 2 To (UBound(arrSource) - UBound(arrSource) Mod 8) Step 8
.Cells(sRow, 3) = arrSource(s, 1)
.Cells(sRow, 4) = arrSource(s + 1, 1)
.Cells(sRow, 5) = arrSource(s + 2, 1)
.Cells(sRow, 6) = arrSource(s + 3, 1)
.Cells(sRow, 7) = arrSource(s + 4, 1)
.Cells(sRow, 8) = arrSource(s + 5, 1)
.Cells(sRow, 9) = arrSource(s + 6, 1)
.Cells(sRow, 10) = arrSource(s + 7, 1)
sRow = sRow + 1
Next s
End With
NextI:
Worksheets("Total Receiving Yards").Select
Columns("A:K").EntireColumn.Hidden = True
End Sub