+ Reply to Thread
Results 1 to 8 of 8

cell references in UDF

  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    5

    cell references in UDF

    I recently wrote a function that adds a bunch of email addresses together and separates them with commas. I made it dynamic because the number of email addresses in each section is constantly changing. There is a sheet attached so you can see what I'm talking about. There are more rows above and below what I attached, but they are insignificant. Here is the code that I wrote:

    Please Login or Register  to view this content.

    The code works just fine when the range in the function is on the same sheet as the function. But for some reason, if I try to use the function in sheet 2 for example and the email addresses are in sheet 1, I get #value!.......any ideas as to why?
    Attached Files Attached Files

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: cell references in UDF

    Hi thefrogsaysquack,

    It looks as though you haven't coded:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    06-14-2012
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: cell references in UDF

    Sorry, I don't quite understand what you're trying to say

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: cell references in UDF

    thefrogsaysquack,

    Attached is a modified version of your posted workbook. In Sheet2 cell B1 and copied down is this formula:
    Please Login or Register  to view this content.
    I modified your UDF quite a bit. It's good practice to have strongly named (easily identifiable) variable names and they should be declared at the top of any function or subroutine. I used an array to store the data values from the range that is fed to the UDF, so that it doesn't matter what sheet you use the UDF on.

    Here is the modified UDF code:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    06-14-2012
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: cell references in UDF

    Thanks for the reply. Honestly, I have no idea what you wrote lol. It works in the sense that it completes the task, but it adds a comma at the end of the final string if there are empty cells in the range. suggest?

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: cell references in UDF

    Updated code:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-14-2012
    Location
    Richmond, Virginia
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: cell references in UDF

    works perfectly. Thanks.

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: cell references in UDF

    You're very welcome

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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