This is a piece of code I Got.

For Each sh In ActiveWorkbook.Sheets
' below to check if there is a worksheet with the name locally stored data and if there is one then delet

If sh.Name = "Locally Stored Data" Then
Application.DisplayAlerts = False
sh.Delete
Application.DisplayAlerts = True
End If
Next sh

' copys a templatte sheet and then rename it and copy data etc.

Sheets("Temp").Visible = True
Sheets("Temp").Select
ActiveSheet.Copy
ActiveSheet.Name = "Locally Stored Data"
Sheets("Temp").Visible = False
Sheets("Data").Visible = True
Range("A9").Select
Selection.CurrentRegion.Select
Selection.Copy
Sheets("Locally Stored Data").Select
Range("A2").Select


It gets to the highlighted part and then copys the Sheet temp into a new workbook instead of keeping it in the same workbook. any ideas?