try
Sub test()
Dim a, x, i As Long, ii As Long, n As Long, r As Range
If Not [isref(myresult!a1)] Then Sheets.Add(, Sheets("sheet4")).Name = "MyResult"
With Sheets("sheet4")
x = Filter(.[transpose(if(m1:m10000="accountable operator",row(1:10000)))], False, 0)
If UBound(x) = 0 Then MsgBox "somthing is wrong": Exit Sub
ReDim Preserve x(UBound(x) + 1)
x(UBound(x)) = .Range("b" & Rows.Count).End(xlUp).Row
ReDim a(1 To .Rows.Count, 1 To 4)
For i = 0 To UBound(x) - 1
n = n + 1
a(n, 1) = .Cells(x(i) + 1, "m")
a(n, 2) = .Cells(x(i) + 1, "c")
a(n, 3) = .Cells(x(i) + 1, "d")
a(n, 4) = .Cells(x(i) + 4, "e")
If x(i + 1) - x(i) > 7 Then
For ii = x(i) + 6 To x(i + 1) - 4
n = n + 1
a(n, 2) = "'" & .Cells(ii, "e")
a(n, 3) = "'" & .Cells(ii, "f")
a(n, 4) = .Cells(ii, "h")
Next
End If
Next
End With
With Sheets("myresult").[a1:d1].Resize(n + 1)
.CurrentRegion.Clear
.Rows(1).Font.Bold = True
.Rows(1).Value = [{"Accountable Operator","Date Raised","Time Raised","Description"}]
.Rows(2).Resize(n) = a
.Columns("b:d").Borders.Weight = 2
For Each r In .Columns(1).SpecialCells(2, 2)
r.Resize(, 4).Font.Bold = True
r.Resize(, 4).BorderAround Weight:=3
Next
.BorderAround Weight:=3
.EntireColumn.AutoFit
.Parent.Select
End With
End Sub
Edit:
Now I see what you meant by "Do not mind if this area is blank or if it repeats the line above"...
Bookmarks