#Struggling Variable file name & Loop

drno3228

New Member
Joined
Dec 11, 2014
Messages
12
Hey,

I'm trying to edit the following VBA code so that the file I open becomes variable:
Sub ReinvestmentIncome_Check()
Dim wb As Workbook
Dim Lmonth As Date
Dim Smonth As Date
Dim Yr As Date
Dim Syr As Date
Lmonth = ActiveSheet.Range(A2).Value
Smonth = ActiveSheet.Range(B2).Value
Yr = ActiveSheet.Range(C2).Value
Syr = ActiveSheet.Range(D2).Value
Set wb = Workbooks.Open("J:\CF_NIM\" & Yr & " Fair Value Analysis\Monthly Fair Value Attribution\" & Lmonth & " " & Syr & "\" & Smonth & " " & Syr & " FV Return Estimation & Adj Detail.xls")

ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("LC & Float").Select
Windows("Nfloat Attribution History.xlsm").Activate
ActiveCell.FormulaR1C1 = _
"=-'[Feb 11 FV Return Estimation & Adj Detail.xls]LC & Float'!R62C12/10^6"
ActiveCell.Offset(0, 2).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=-SUM('[Feb 11 FV Return Estimation & Adj Detail.xls]LC & Float'!R62C12:R142C12)/10^6-RC[-25]"
ActiveCell.Offset(1, 0).Range("A1").Select

End Sub

For some reason, I keep getting an error when I attempt to run. I also need to incorporate a loop at some point so that it runs for all twelve months.

A2:D2 are just January; Jan; 2011; 11

Thanks in advance.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Do you want to process 12 workbooks for a given year?

What values are exactly is in A2:D2 as seen in the formula bar (not displayed in the cell)? Are they dates like 1/1/2011 or Text and Numbers for the Month and Year?

What error do you get and what line in the code is highlighted when you Debug it?
 
Upvote 0
I want to process all twelve months in a single workbook. 1 row per a month. The file path and file that it pulls from will change based on the month.

Cells A2:D2 are just January; Jan; 2011; 11
Cells A3:D3 are February; Feb; 2011; 11
Cells A4:D4 are March; Mar; 2011; 11
...All the way through December.

I can't give you the error, as I'm on my mac at home :(


 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

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