Setting a range equal to a group of variables

grexcelman

Board Regular
Joined
Mar 1, 2015
Messages
50
Not sure where my syntax is wrong here. I've been trying to concat a few variables into a range based off the location in a shared folder for my coworkers to use when updating a sheet. Hopefully someone can point me in the right direction. When I've checked each variable by using msgbox within the function, each one checked out ok until I get to the range varaible and that's where the function stops and I get a #Value! error with no msgbox popup.

Code:
function test()
Dim location As String
Dim monthly_file As String
Dim function_tb As String
Dim linkfile As Range

location = "My drive address"
monthly_file = "My current month"
function_tb = "charity'!A10:X25"
Set linkfile = Range(location & monthly_file & function_tb)
msgbox linkfile
 
What happend if you replace the variables with literals?

Code:
Set linkfile = Workbooks(" Monthly Trend _ February Reporting_BD6.xlsx").Worksheets("Marketing Monthly Trend GL").Range("$A$12:$BJ$63")
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
In what module does the code appear?

In the Immediate window, enter

Code:
? Workbooks("Monthly Trend _ February Reporting_BD6.xlsx").Name

What do you see?
 
Upvote 0
In what module does the code appear?

In the Immediate window, enter

Code:
? Workbooks("Monthly Trend _ February Reporting_BD6.xlsx").Name

What do you see?

Run-time error '9':
Subscript out of range

from what i can tell the name definitions all look correct and my workbook I'm pointing to is still open.
 
Upvote 0
I apologize if this has already been answered in another post, but I have a question that may be relatively simple for someone on here:

Can someone provide the formula that will place a specific dollar amount dependent on the range of another cell.
For example, if F16 is between $10000-$15000, then E19 equals $700.
 
Upvote 0
@Spintzer: Please start your own thread.

@grexcelman: That means there is no workbook open with that exact name (aside from case). Computers are annoyingly literal.
 
Upvote 0
It printed in the immediate window fine. The worksheet range is likely the issue. whats the appropriate way to print that? same syntax
in that window as for workbooks?

this produced an error:
Code:
? Worksheets("Marketing Monthly Trend GL").range("$A$12:$BJ$63").Name
 
Upvote 0
It printed in the immediate window fine. The worksheet range is likely the issue. whats the appropriate way to print that? same syntax
in that window as for workbooks?

this produced an error:
Code:
? Worksheets("Marketing Monthly Trend GL").range("$A$12:$BJ$63").Name

I also tried testing the full line in the immediate window:
Code:
? Workbooks("Monthly Trend _ February Reporting_BD7.xlsx").Worksheets("Marketing Monthly Trend GL").Range("$A$12:$BJ$63").Name
it kicked out this error:
Run-time error '1004': Application-defined or object-defined error.
 
Upvote 0
Code:
? Workbooks("Monthly Trend _ February Reporting_BD7.xlsx").Worksheets("Marketing Monthly Trend GL").Name
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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