Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Range problem

I created a function in excel and I want to use it in my VBA and I don't know
how to refer to the range

Function PD(func As String, ai As Double, Zi As String, rng As Range)

Say my range is A1:A4

How do I set rng = A1:A4


Any help

  #2   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default Range problem

rng = Range("A1:A4")

You may need to reference the sheet as well:
rng = Sheets("mysheet").Range("A1:A4")

"Ali Baba" wrote:

I created a function in excel and I want to use it in my VBA and I don't know
how to refer to the range

Function PD(func As String, ai As Double, Zi As String, rng As Range)

Say my range is A1:A4

How do I set rng = A1:A4


Any help

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Range problem

Ali,

When you call the function from your worksheet, simply pass it the address
of the range as the fourth parameter:

=PD("Func Input",1234.56, "Zi input", A1:A4)

or they could all be range references: Excel will take them in order an
assign them to the variables:

=PD(B1,C1,D1,A1:A4)


When calling the function from VBA, you need to be a little better at
specifics:

MyValue =PD("Func Input",1234.56, "Zi input", Range("A1:A4"))

myValue=PD(Range("B1"),Range("C1"),RAnge("D1"),Ran ge("A1:A4"))

It may also be necessary to specify which worksheet object the range object
comes from. To fully identify the range , change Range(...) to
Worksheets("Sheet name").Range("A1:A4")


HTH,
Bernie
MS Excel MVP



"Ali Baba" wrote in message
...
I created a function in excel and I want to use it in my VBA and I don't
know
how to refer to the range

Function PD(func As String, ai As Double, Zi As String, rng As Range)

Say my range is A1:A4

How do I set rng = A1:A4


Any help



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range problem Ali Baba Excel Programming 1 September 10th 05 01:10 AM
Range problem David Gerstman Excel Programming 2 May 24th 05 07:11 PM
getting value of range problem Grant Excel Programming 1 September 23rd 04 06:20 AM
Range problem Mark[_36_] Excel Programming 6 February 12th 04 01:22 PM
Used Range Problem Charles Williams Excel Programming 0 August 4th 03 08:30 AM


All times are GMT +1. The time now is 10:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"