Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

excel vba

ResolvedVersion 2010

Freddie has attended:
Excel VBA Introduction course

Excel VBA

Hi guys,

I am having a problem with the below code. What I'm trying to do is copy sheets from one workbook - filter by current month and copy onto another (already opened workbook). My macro falls over when it goes to Set y = ActiveWorkbook.Open

Are you able to advise? All I want to do is switch to the following workbook "L:\ClientInterest\BAD-STATIC DATA\Static Data CHECKS\Serena\MASTER_NA.xlsx") - without the need to reopen it again?


Sub CopySheets()

Dim i As Workbook

Set i = Workbooks.Open("L:\ClientInterest\BAD-STATIC DATA\NA-rates\BAD-NA Interest set-up_ 22_07_2015.xlsm")

Sheets(Array("LBARATEF", "LBAPARIF", "LBAMKTCF")).Copy
ActiveWorkbook.SaveAs ("L:\ClientInterest\BAD-STATIC DATA\Static Data CHECKS\Serena\MASTER_NA.xlsx")
Sheets("LBARATEF").Select

i.Close

Sheets("LBARATEF").Range("A1:D300000").AutoFilter Field:=3, Criteria1:=xlFilterThisMonth, Operator:=xlFilterDynamic
Cells.Select
Selection.Copy
Worksheets.Add(After:=Worksheets("LBAPARIF")).Name = ("LBARATEF2")
Sheets("LBARATEF2").Select
ActiveSheet.Paste
Sheets("LBARATEF").Delete

Dim x As Workbook
Dim y As Workbook

Set x = Workbooks.Open("L:\ClientInterest\BAD-STATIC DATA\Static Data CHECKS\52 CCY + Market for Static Data Checks.xlsx")
Set y = ActiveWorkbook.Open

x.Sheets("CODINGS").Range("A1:B739").Copy
y.Sheets("LBAMKTCF").Range("C312:D470").PasteSpecial
y.Sheets("LBARATEF2").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial

x.Close

Best regards

Freddie

RE: Excel VBA

Hi Freddie,

Thank you for the forum question.

Set y = ActiveWorkbook.Open

This line is not working because you cannot open the active workbook. If you want to jump between open workbooks you need to refer to their names.


Set y=Workbooks("MASTER_NA.xlsx")
y.Sheets("LBAMKTCF").Range("C312:D470").PasteSpecial
y.Sheets("LBARATEF2").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial



Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

Wed 5 Aug 2015: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Select Single Data Marker

To select a single data marker in a chart, ie line, bar or column;
After you have pressed Ctrl+Click (to select the entire chart) you can press the Up or Down arrows to select a data series, then press the Left or Right arrow to select a data point within that series.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.13 secs.