Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a Range parameter to a called Excel Function? 1

Status
Not open for further replies.

maxpi

Technical User
Jan 18, 2001
10
US
Trying to write a function that calls another function and passes a Range parameter. The following code works

Function CallMxvSMA()
last = "E10"
bars = 2
CallMxvSMA = MxvSMA(Range(last), bars)
End Function

but it is not quite what I need, I need to formulate the range in a more complicated fashion something like:

last = "EMAlast.Offset(EMABars, 0)" 'where EMAlast is an Excel range.

I can't seem to pass anything complicated like that as a range parameter to the called function. Anybody got game?
 
Here is a simple example how to pass a range object.

Private Sub test()
Dim MyRange As Range
Dim MyArea As String

MyArea = "A1"

Set MyRange = ActiveSheet.Range(MyArea)

Call TestRange(MyRange)
End Sub

Private Function TestRange(PassedRange As Range)
MsgBox PassedRange.Value
TestRange = PassedRange.Value
End Function

Let me know if this doesn't help. It is important that you Dim everything properly, this will help flag errors.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top