The main thing is that you've got it working.
You have to remember to use the reference to that particular sheet at the proper places.
Sheets("Sheet1").Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
more than likely will give wrong results if another sheet is the active sheet.
It needs the 2nd reference like
Sheets("Sheet1").Range("A1:A" & Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
That's where the "sh1" comes in, a lot less typing!