Adding worksheet to a range variable

swonghk

New Member
Joined
Oct 20, 2019
Messages
2
Hi I tried to add the worksheet information to a range variable which was passed from a main routine. "Received_range" is the range variable received and all of the three lines below has resulted in error.

a. Set localrange = Sheets("Sheet1").received_range
b. Set localrange = Sheets("Sheet1").Range("received_range")
c. Set localrange = Sheets("Sheet1").Range(received_range)

What should I do to correct it?

Subroutines are as follows:

Sub testing()
Dim passing_range As Range
rng = Range("A1")
Call calledpro(passing_range)
End Sub


Sub calledpro(received_range As Range)
Dim localrange As Range
'trial 1
Set localrange = Sheets("Sheet1").received_range
'trial 2
Set localrange = Sheets("Sheet1").Range("received_range")
'trial 3
Set localrange = Sheets("Sheet1").Range(received_range)
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi & welcome to MrExcel.
How about
Code:
Sub testing()
Dim passing_range As Range
Set passing_range = Range("A1")
Call calledpro(passing_range)
End Sub


Sub calledpro(received_range As Range)
Dim localrange As Range
Set localrange = Sheets("Sheet1").Range(received_range.Address)
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,412
Messages
6,119,365
Members
448,888
Latest member
Arle8907

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