Results 1 to 10 of 11

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,319
    Rep Power
    10
    “AdeelSolution1” ( )


    Simple modifications to the second thing , for now, just to see if we can get a result from DisplayFormat
    I will forget the sheet referring, as that is not of interest to the final solution,
    and
    I will do some simple use of DisplayFormat, for example, the DisplayFormat.Interior.ColorIndex of cell C17

    Example, change
    Code:
    Sub DoDisplayFormat(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
    to
    Code:
    ' Second thing
    Sub DoDisplayFormat(ByVal Rng As Range, ByVal Sht As String)
    Stop  '  It wont
     Let Rng.Offset(0, 2).Value = ""
     Let Rng.Offset(0, 2).Value = "For cell " & Rng.Address(0, 0) & ", you have a DisplayFormat.Interior.ColorIndex of  " & Rng.DisplayFormat.Interior.ColorIndex
    End Sub
    This appears to be giving me sensible results in Office Excel 2013:







    Towards a final solution for Adeel
    We want a replacement for a formula of this form =sum_color(D6:G15,C17)
    So we need
    a second range argument in the first thing,
    [color=blueviolet]Function[/color] DoSomeColor(ByVal RngA As Range, ByVal RngB As Range) As String
    and
    in the second thing we no longer need to be taking in a sheet name, but do need to take in a second range argument.
    Sub SomeColor(ByVal RgA As Range, RgB As Range)

    The rest of the modification is just doing something similar in the second thing to Adeel’s original function.
    Code:
    '   '   From  Adeel  spreadsheet    '  =sum_color(D6:G15;C17)    '    http://www.eileenslounge.com/viewtopic.php?p=300075#p300075
    ' First thing
    Function DoSomeColor(ByVal RngA As Range, ByVal RngB As Range) As String
     Evaluate "='" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & "'!DisplayFormatUDF.SomeColor(" & RngA.Address & ", " & RngB.Address & ")"         '
    ' Evaluate "SomeColor(" & RngA.Address & ", " & RngB.Address & ")"  ' Shortened version relying on default
    End Function
    
    
    ' Second thing
    Sub SomeColor(ByVal RgA As Range, RgB As Range)
    Stop  '  It wont
    Dim Vee As Long, Sea As Range
        For Each Sea In RgA
            If Sea.DisplayFormat.Interior.ColorIndex = RgB.DisplayFormat.Interior.ColorIndex Then
             Let Vee = Vee + Sea.Value
            Else
            End If
        Next Sea
     Let RgB.Offset(1, 2).Value = ""
     Let RgB.Offset(1, 2).Value = Vee
    End Sub
    That seems to give the correct result of 54




    ( For comparison, see the results of 54 here:
    http://www.excelfox.com/forum/showth...ll=1#post18404
    )







    Share ‘DisplayFormatInUDFAdeel1.xlsm’ https://app.box.com/s/5nvqh5r8pggc11ulz4lti3yhk39b9wda
    Last edited by DocAElstein; 10-21-2022 at 07:12 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    _...KILL A MODERATOR!!

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
  •