I am a pretty new to VBA, so sorry if problem is obvious for more experienced users. I tried to read couple of answers to similar question, and fix the problem but still facing the same problem.
My code is:
Workbooks("XXX.xls").Activate
' Setting column width
Workbooks("XXX.xls").Worksheets("XXX").Cells.Select
Selection.ColumnWidth = 10
' Filtering XXX funds
Workbooks("XXX.xls").Worksheets("XXX").Rows("1:1").Select
Selection.AutoFilter Field:=3, Criteria1:="=*XXX*"
' Add new sheet and rename it
Sheets.Add After:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "XXX_F"
'Copying needed information
Workbooks("XXX.xls").Worksheets("XXX").Range("A1:C1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
The error I am getting is "Run Time Error '1004': Select method of Range Class failed" on the third line from the bottom. I tried to fix it by adding this line (i.e. activating workbook I want to work with first):
Workbooks("XXX.xls").Activate
Also I used explicit references in my code, like:
Workbooks("XXX.xls").Worksheets("XXX").Range("A1:C1").Select
I understand that it is better not to use .Select method in my code at all. But it is not the first time I am getting this error, and I just want to understand VBA's logic. As I understand Excel just do not understand to which sheet I am referring, but I do not understand why - as I have activated the workbook I need (I have a couple of workbooks opened) and using explicit references. If you could please explain in detail why this error occurs (i.e in which point in time Excel confuses), I will be very grateful!
Thanks to everyone for help in advance!