+ Reply to Thread
Results 1 to 3 of 3

The range as an argument of a UDF

  1. #1
    Forum Contributor
    Join Date
    01-16-2014
    Location
    London
    MS-Off Ver
    Excel 2003 Excel 2010
    Posts
    189

    The range as an argument of a UDF

    Hi everyone, I suspect the following reference to the range is problematic: Range("Rng1").Cells(1,2). In this function, Rng1 is an argument. Does this mean that VBA tries to find the actual name called 'Rng1', rather than the pass-through from the argument?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: The range as an argument of a UDF

    Why are you mixing syntaxes? As you have it now, Rng1 is dimensioned as a range object, there is no need to use the Range keyword to make it more of a range.

    The first syntax you use is the one I use most -- Rng1.cells(1,1)

    You are correct about the second syntax -- Range("Rng1"). VBA is looking for a named range in the activesheet/workbook that is named "Rng1". It is not looking for the Rng1 object variable defined in the scope of the procedure.

    The syntax I would use would be Myfunction=rng1.cells(1,1) + rng1.cells(1,2)
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    01-16-2014
    Location
    London
    MS-Off Ver
    Excel 2003 Excel 2010
    Posts
    189

    Re: The range as an argument of a UDF

    Hi MrShorty, many thanks for your explanation. I'm new to VBA

    I made a function today. The function uses the range in the 2nd form Range("xxx")., which failed to work. Good to gradually correct these mistakes.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] ByRef argument type mismatch / Passing array as a function argument
    By pzling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2012, 06:23 PM
  2. Replies: 3
    Last Post: 04-28-2010, 05:54 PM
  3. Range with Cells as an argument
    By ctor in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-03-2009, 07:07 AM
  4. .Range cant take long argument
    By christianlebe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2008, 12:06 AM
  5. [SOLVED] Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1