Setting Up a Macro that will work with files of different names

HobbesNYC

New Member
Joined
Aug 8, 2012
Messages
13
Hello All,

I'm trying to build a Macro that will automate the process of pulling information from another workbook. Say "August Accounts" from "August Returns". The information is always in the same place, however, each month, when the new books come out, I don't want through the code line by line by line renaming each file. I have the code set up as so (it repeats some 40 times)


Range("N6").Select
Windows("Draft Copy of CAP-AWM_201206.xlsx").Activate
ActiveSheet.Range("$A$1:$BY$2432").AutoFilter Field:=75, Criteria1:=Workbooks("Draft Copy of Business Reporting_Jun2012_lg (3).xlsx").Sheets("PB ECR Exceptions by Region").Range("$A$6")
Columns("BS:BS").Select
Selection.End(xlDown).Select
Selection.Copy
Windows("Draft Copy of Business Reporting_Jun2012_lg (3).xlsx").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False




Any ideas? I'm thinking maybe I should give a message box asking to name the file and use that as a variable or something but I don't know how to do that.

Thank you!!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
You can identify the name of the workbooks as follows, if only the dates change:

Code:
Sub HobbesNYC()

Range("N6").Select
Workbooks("Draft Copy of CAP-AWM_" & Format(DateAdd("m", 0, Date), "yyyymm") & ".xls").Activate
ActiveSheet.Range("$A$1:$BY$2432").AutoFilter Field:=75, Criteria1:=Workbooks("Draft Copy of Business Reporting_Jun2012_lg (3).xlsx").Sheets("PB ECR Exceptions by Region").Range("$A$6")
Columns("BS:BS").Select
Selection.End(xlDown).Select
Selection.Copy
Workbooks("Draft Copy of Business Reporting_" & Format(DateAdd("m", 0, Date), "mmmyyyy") & "_lg (3).xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

End Sub

Note the 0 in the DateAdd format indicates the current month, -1 would mean the previous month, 1 next month and so on.
 
Upvote 0

Forum statistics

Threads
1,216,134
Messages
6,129,070
Members
449,485
Latest member
greggy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top