Results 1 to 10 of 24

Thread: UDF that can change values in cells other than the cell in which the UDF is used

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,456
    Rep Power
    10

    UDF that can change values in cells other than the cell in which the UDF is used

    UDF that can change values in cells other than the cell in which the UDF is used

    This Tips Thread was inspired by this one posted by Rick Rothstein
    I have referred to that posting from Rick quite a few times when showing people how to use a UDF to do things with a UDF in cells other than that in which the UDF is, and mostly pretty impressed they have been too. ( Those that weren’t impressed were those that did not believe it and never tried…. )


    I finally got around to trying to get my head around this, and here is my take on it. If you are only interested in seeing the working examples, then jump to post 4 , or post a question in the main Excel Help forum question sub forum
    https://www.excelfox.com/forum/forum...p/2-Excel-Help

    If you are familiar with Ricks ways of doing this, then basically I am using his solutions but just not using the hyperlink. There’s not much more to it then that. I came there from a long winded way which I am discussing in the next post, but the key to it working is based on, or using, the way Rick used the Evaluate within the coding for the UDF that is in the worksheet

    _______ Evaluate__ "SomeOtherProcedureToDoAnythingAnywhere(ArgY, __)"


    Here again below, the solution a bit more fully: Below is the coding as you would write it in a normal code module , assuming that the Function MainUDF( ) is the UDF which you would use in the usual formula type way in a worksheet cell like __ = MainUDF( )
    http://i.imgur.com/58IFQoQ.jpg

    ___Function MainUDF(__) ' UDF to be used in a worksheet cell like__ = MainUDF(ArgX)
    ____ ' any coding to do anything not related to changing things in the worksheet in which the UDF is used
    ____ '
    _______ Evaluate__ "SomeOtherProcedureToDoAnythingAnywhere(ArgY, __)"
    ____ '
    ____ ' any coding to do anything not related to changing things in the worksheet in which the UDF is used
    ____ '
    ___End Function







    Simplest Working Example:
    The simplest example is something like the following:
    Copy both procedures to a normal code module , …_
    Code:
    '   Paste both procedures in a normal code module, then  type  =ChangeNextCell()  in any cell followed by  Enter
    Function ChangeNextCell()
    '  Call NextCell          '  This wont work. We will be on the same dependancy in the called procedure and cell dependancies are already calculated so attempts to access cells will be screwed up
     Evaluate "NextCell()"    '  The dependance tree is recalculated for the procedure  NextCell()  which  is excecuted from a copy of the procedure not dependant on the spreadsheet update cycle in progress for the excecution of the function  ChangeNextCell()
    End Function
    Sub NextCell()
     ActiveCell.Offset(0, 1).Value = "Next cell."         '   Excel has a memory of the last  Active Cell  and does not rely on dependance to the spreadsheet for this macro to run
    End Sub
    _... then type in any cell the function _ =ChangeNextCell() _ then _ Enter

    ChangeNextCell.JPG : http://i.imgur.com/nqHHEfb.jpg https://imgur.com/nqHHEfb


    ChangeNext Cell.JPG : http://i.imgur.com/iAQFUrj.jpg https://imgur.com/iAQFUrj


    Change Next Cell.JPG : http://i.imgur.com/V7Lowxp.jpg https://imgur.com/V7Lowxp





    In the next post some attempt to examine what’s going on. It is not complete; I may need to come back again on this one
    Last edited by DocAElstein; 09-06-2025 at 01:24 PM.

Similar Threads

  1. Question on UDF LookUpConcat
    By K2` in forum Excel Help
    Replies: 4
    Last Post: 05-07-2013, 10:25 PM
  2. Trouble implementing UDF's
    By ProspectiveCounselor in forum Excel Help
    Replies: 4
    Last Post: 05-06-2013, 08:07 PM
  3. Insert Picture in a Cell UDF
    By Admin in forum Download Center
    Replies: 10
    Last Post: 12-07-2012, 04:49 PM
  4. UDF to Create In-Cell Chart in Excel
    By Admin in forum Download Center
    Replies: 0
    Last Post: 08-13-2011, 09:53 AM

Posting Permissions

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