98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Excel VBA
Excel VBA
Resolved · High Priority · Version 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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Pivot table groupingIf you want to group items in a pivot table together, simply highlight the labels for the fields either with the shift key (if adjacent)or with the contral key if they are not next to each other. |