0

I want to edit this macro to overwrite previous data in another workbook without prompting. See attached code. Any help would be greatly appreciated.

Sub AV()

    Workbooks.Open Filename:="T:\Cleveland\Avon\Monthly Sales\Monthly Sales 2018.xls"

    Windows("Sales_By_Day_Location Analysis.xlsm").Activate
    Sheets("AV").Select
    Range("A1:AC88").Copy

    Windows("Monthly Sales 2018.xls").Activate

    Sheets("Avon").Select
    Range("A1:D1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats

    Application.CutCopyMode = False 'esp

End Sub
1
  • 1
    Perhaps Application.DisplayAlerts = False at the beginning of the sub (setting it to True at the end) would work. Commented Jan 8, 2018 at 13:39

1 Answer 1

1

As per comments from John, and after tidying up your code a little, I believe something like the code below would do what you are expecting:

Sub AV()
Application.DisplayAlerts = False

Workbooks.Open Filename:="T:\Cleveland\Avon\Monthly Sales\Monthly Sales 2018.xls"
Workbook("Sales_By_Day_Location Analysis.xlsm").Worksheets("AV").Range("A1:AC88").Copy
Workbook("Monthly Sales 2018.xls").Sheets("Avon").Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats

Application.CutCopyMode = False 'esp
Application.DisplayAlerts = True
End Sub

You should attempt not to use Activate or Select statements. Also your copy range is a lot bigger than your paste range, so for the purpose of this answer I've changed the paste range to A1.

If you want to then save the workbooks and close it without a prompt, you could do something like:

Workbook("Monthly Sales 2018.xls").Close SaveChanges:=True
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.