Naming a range from another workbook

grexcelman

Board Regular
Joined
Mar 1, 2015
Messages
50
Having some difficulty naming the ranges in my code. Ultimately trying to run a Vlookup but I've tried breaking up the pieces of the range location to help simplify and find the error in my range value.

Code:
Function ann_calc(acct As String, func As Long, term As Variant)
Dim driveloc As String
driveloc = "Z:\Management\Expense Project\2015_figures\"
filename1 = driveloc & "Jan Only File.xlsm"
filename2 = driveloc & "Feb Only File.xlsm"
tab1 = "Expenses by Function'!"

Dim datarangegb1 As Range

Set datarangegb1 = Range(filename1 & tab1 & "$B$9:$K$44")

total1 = Application.WorksheetFunction.VLookup(acct, datarangegb1, func, False)

ann_calc.value = total1

Can't seem to isolate where I'm going wrong here.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You can't do that in VBA - the source workbooks have to be open for you to assign their ranges to a Range object.
 
Upvote 0

Forum statistics

Threads
1,216,085
Messages
6,128,732
Members
449,465
Latest member
TAKLAM

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