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. #17
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    Question from the Web: ……. I need a UDF to change other cells
    https://stackoverflow.com/q/8520732/4031841
    https://stackoverflow.com/a/79788169/4031841

    ……I would really like it if there was some way I could just fill in one square with my formula, and Excel would fill in the squares below as needed…..

    I have not quite figured exactly what was wanted,

    But I can give a very simple alternative coding to get a UDF to change other cells, directly in terms of simplicity, ( possibly very indirectly in terms of what is happening behind the scenes.: What is going on here is sometimes considered as VBA having some redirection and ended up a bit lost, or rather does not know where it came from ).


    _ First put these codings in a normal module
    Code:
    Option Explicit
    ' This is the main UDF, used by writing in a cell something of this form   =UDF_Where(E3:E5)
    Function UDF_Where(ByVal Cels As Range) As String      ' Looking at this conventionally, a string is likely to be returned  by this function in the cell you put the UDF into
     Let UDF_Where = "This is cell " & ActiveCell.Address & ", where the UDF is in" ' Conventional use of UDF to change value of the cell that it is in
    Worksheets("Derek").Evaluate Name:="OverProc(" & Cels.Address & ")"             ' Unconventional use of a UDF to change other cells    ' The  Evaluate(" ")  thing takes the syntax of  Excel spreadsheet   So I need this sort of thing    Cels.Address   to give me the  string bit like  $D$2
    End Function
    
    
    Sub OverProc(Cels As Range) ' This can be a  Sub  or  Function
    Dim SteerCel As Range
        For Each SteerCel In Cels
         Let SteerCel = "This is cell " & SteerCel.Address & ", from the range I passed my UDF (" & Cels.Address & ")"
        Next SteerCel
     ActiveCell.Offset(10, 0) = "This cell is 10 rows down from where my UDF is"
    End Sub
    
    You will need to name a worksheet "Derek"., (That is not a general requirement but just ties up with the demo coding above and in the uploaded workbook)

    _ Now write the formula/function in a cell
    In the worksheet named "Derek", type in any cell, for example D2, the following

    =UDF_Where(E3:E5)

    , then hit Enter

    You should see these results

    https://i.postimg.cc/QtSFHPR1/Derek.jpg Derek.JPG










    ‘StackOverflowUDFChangeOtherCells.xls’ https://app.box.com/s/knpm51iolgr1pu3ek2j96rju8aifu4ow
    Last edited by DocAElstein; 10-12-2025 at 12:06 AM.

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
  •