save and overwrite worksheet

marc005

Board Regular
Joined
Apr 21, 2013
Messages
58
We I run the below code:

Sub Macro1()
Sheets("Historyt").Select
Sheets("Historyt").Copy Before:=Workbooks("Merg.xlsm").Sheets(1)
End Sub

and a worksheet called "Historyt" already exist in the file Merg.xlsm
it always create Historyt(2). I dont want that. I want is to overwrite "Historyt"
How can this be achieved?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
I think you need to delete the existing sheet first with something like:-

Code:
Workbooks("Merg.xlsm").Sheets("Historyt").Delete

I hope this helps!
 
Upvote 0
Or maybe something like this:-

Code:
Sub CopyWorkSheet()
    Dim WB1 As Workbook
    Dim WB2 As Workbook
    Set WB1 = Workbooks("ThisBook.xlsm") ' <<< Change to this WorkBook name.
    Set WB2 = Workbooks("Merg.xlsm")
'   Copy from WB1 to WB2
    WB1.Sheets("Historyt").Copy _
        Before:=WB2.Sheets(1)
End Sub

I hope this helps!
 
Upvote 0

Forum statistics

Threads
1,217,360
Messages
6,136,102
Members
449,991
Latest member
IslandofBDA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top