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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,638
Office Version
365
Platform
Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
33,638
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,085,307
Messages
5,382,846
Members
401,807
Latest member
xlWatcher

Some videos you may like

This Week's Hot Topics

Top