Results 1 to 10 of 11

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. #7
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,319
    Rep Power
    10
    I forgot about this Blog tip thread for a while. …

    The reason for that was that I answered a few threads, where someone asked for help because something was not doing what they wanted, and the reason for that was that they were trying to get a UDF to change the value of another cell, or something very similar.
    My solution seemed to work. Sometimes the OP seemed happy. But more often than not, I got a lot of hate from some senior member, “expert Guru”, Moderator, or similar, insisting that a UDF cannot change the value of any cell other than the one it is in.




    It’s about 2 years later now. Maybe it’s safe to post something about it again.
    In the meantime, I still don’t have any newer versions of Office/ Excel, so maybe I will post a very simple example, and ask people to test it for me on newer versions. I won’t present it as "a UDF that can change the value of another cell, other than the one the UDF is in".

    See how it goes.


    I made a much simplified sample file, as enclosed …… This is what I would like you to try for me please:
    Download and open the uploaded file, then
    enable macros and then
    type anything in cell A1, then tell me what happens.

    _.________________________________________________ ______________________________
    EDIT: Or, alternatively, if you prefer not to risk downloading the file
    Please do this
    In a new virgin File, insert a normal code module and put this coding in it

    Code:
    Option Explicit
    Function WotsThereWhere(ByVal Rng As Range) As String
     Evaluate "='" & ThisWorkbook.Path & "\TryThisPlease.xls'!Modul1.YouNameIt(" & Rng.Address & ", """ & ActiveSheet.Name & """)"          '    Evaluate "=YouNameIt(" & Rng.Address & ", """ & ActiveSheet.Name & """)"    '    : Debug.Print "=YouNameIt(" & Rng.Address & ", """ & ActiveSheet.Name & """)"    '  gives   YouNameIt($A$1, "Sheet1")
    End Function
    Sub YouNameIt(ByVal Rng As Range, ByVal Sht As String)
    Stop  '  It wont
     Let Rng.Offset(0, 2).Value = ""
     Let Rng.Offset(0, 2).Value = "You wrote " & Rng.Value & " in cell " & Rng.Address(0, 0) & ",  in worksheet " & Sht
    End Sub
    The first function can be simplified if relying on defaults
    Code:
    Function WotsThereWhere(ByVal Rng As Range) As String
    ' Evaluate "='" & ThisWorkbook.Path & "\TryThisPlease.xls'!Modul1.YouNameIt(" & Rng.Address & ", """ & ActiveSheet.Name & """)"          '    Evaluate "=YouNameIt(" & Rng.Address & ", """ & ActiveSheet.Name & """)"    '    : Debug.Print "=YouNameIt(" & Rng.Address & ", """ & ActiveSheet.Name & """)"    '  gives   YouNameIt($A$1, "Sheet1")
     Evaluate "YouNameIt($A$1, ""Sheet1"")"  ' Shortened version relying on default
    End Function
    




    Feedback so far

    http://www.eileenslounge.com/viewtop...ff4995#p280303








    Any Other Threads doing something similar


    https://stackoverflow.com/questions/...nal-formatting
    https://www.mrexcel.com/board/thread...a-udf.1154593/
    https://www.eileenslounge.com/viewto...300091#p300091
    Attached Files Attached Files
    Last edited by DocAElstein; 10-23-2022 at 03:06 PM. Reason: Theads doing something similar links added

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
  •