0

Workbook x is open.

I want to:

  • Open Excel workbook y (the filepath is in cell "B2" of the macro tab of workbook x).
  • Copy A3:A26 from macro tab of workbook x, and paste into M41:M63 in the summary tab of workbook y.

The problem is with the B2 filepath name. I think I need to specify to pull the text from B2 to open the correct workbook.

The error message is

Sorry, we couldn't find B2.xlsx

Sub Foo()

Dim x As Workbook
Dim y As Workbook

Set y = Workbooks.Open("B2")

x.Sheets("Macro").Range("A3:A26").Copy

y.Sheets("Summary").Range("M41:M63").PasteSpecial

End Sub

1 Answer 1

1

Try the following ... assumes the Sheet in Workbook x is actually called "Macro" (you also have a Sheet in Workbook y with the same name?) ... you also need to set the value for x which this does:

Sub Foo()
    Dim x As Workbook
    Dim y As Workbook
    Set x = ActiveWorkbook
    Set y = Workbooks.Open(x.Sheets("Macro").Range("B2"))
    x.Sheets("Macro").Range("A3:A26").Copy
    y.Sheets("Summary").Range("M41:M63").PasteSpecial
End Sub
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.