On error resume next will not get rid of the error if there are no visible cells.
You need to change this line

If Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Count > 2 Then