@Scott Holtzman provided the solution in a comment:
I would just adjust the following, since the OP asked for dynamic
range names, Set range1 = Range("A1:B" & Range("B" &
Rows.Count).End(xlUp).Row) to get the real last cell in column B. Do
the same for column F as well