Cell Reference in Macro

iamphil26

Board Regular
Joined
May 16, 2012
Messages
52
I've got this line in a macro:

Workbooks.Open Filename:= _
"\\IN-ACCOUNTING1\Accounting\EOP_workpapers\Books\AAL\" & Worksheets("Sheet2").Cells(F14) & "\" & Range(Sheet2!F13) & "\CN3008R_CGS.csv"

I'm trying to use cells as references to part of the file path (Sheet2! F14 contains "2012" and Sheet2! F13 contains "04"). What's the right way to do this? I tried doing the references two different ways here, because I don't know the right way to go about this. My apologies, my knowledge of VBA is pretty limited. Please feel free to ask any further questions for clarification.

Thanks guys!

Phil
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try
Rich (BB code):
Workbooks.Open Filename:= _
"\\IN-ACCOUNTING1\Accounting\EOP_workpapers\Books\AAL\"  & Worksheets("Sheet2").Range("F14").Value & "\" & Worksheets("Sheet2").Range("F13").Value  & "\CN3008R_CGS.csv"
 
Upvote 0
Thank you so much for your help! If I were to repeat that line multiple times, but change the file name slightly (to open other similar files), is there something special I need to do? What I'm running into right now is I run the macro, it works just like it should for the first file (which is the code I copied from your post). But when it moves to the next line (Copied from the post, but changed the "CGS" at the end to "CWC" to open a different file), it gives me a run time error and it says that excel cannot update links. It tells me to go to "Edit Links", however, because I don't have links, the "Edit Links" is grayed out. I'm not really sure what's going on here.
 
Upvote 0

Forum statistics

Threads
1,203,681
Messages
6,056,706
Members
444,885
Latest member
Mark Prillman

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