+ Reply to Thread
Results 1 to 3 of 3

Writing a Function

  1. #1
    Registered User
    Join Date
    06-06-2007
    Posts
    53

    Writing a Function

    I'm working on a function that will compare each cell in a range to the cell before it, and return a 0 if they are equal and a 1 if they are different.

    Know how to make the loop to do the comparison, but I am having an issue with using cells on other worksheets. In subroutines, I can use Worksheets("Worksheet Name").Select to change worksheets and then pull data. When I write a function, I cannot change worksheets (even Worksheets("Sheet Name").Cells() doesn't work.)

    What's the trick here? What's the command to change worksheets so I can pull cell data from other sheets for a user-defined function, or is that not possible?

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Use
    Please Login or Register  to view this content.
    No need to select.

    HTH

    Jason

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819
    many say that it is bad practice to access information directly from within a UDF like that. Better might be to pass the range to the function via the argument list. To illustrate
    Please Login or Register  to view this content.
    Then, when you call the function from the spreadsheet, you just reference the range from the other worksheet just like in any other built in function. (=compare1(sheet1!a1,sheet2!a2))

+ 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