20,000+ is pretty close to 32,767, so first thing is to declare NearEnd as LongNearEnd As Long
. Actually, you can declare all variables used as row numbers as Long, there is no gain on performance when you use Integer, and you are less prone to have overflow error.
Secondly, the issue with Worksheets("Group " & Groups).Range("A2:AE2").Offset(r, 0)Worksheets("Group " & Groups).Range("A2:AE2").Offset(r, 0)
line. As mentioned in comments above, it should be either continuation sing in line above "(space)_" or .pastespecial on the end.
And third, you could make code running faster just by replacing For-Next loop with the Object Loop. So, define range:
With Sheets("Sheet1")
Set rng = Range(.Range(NearStart, "AB"), .Range(NearEnd, "AB"))
End With
and then
For Each cl in rng
(....)
nextNext cl
rng and cl declared as Range, of course.
If you have formulas and they don't need to be calculated while macro is running, I should turn of automatic calculation, together with screen flickering. You probably know this, just for the record:
With Application
.ScreenUpdating = False
.Calculation = xlCalculationmanual
End With
and back to xlCalculationAutomaticxlCalculationAutomatic
on the end.