Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Creating function for cell

  1. #1
    Guest

    Default

    How can I change a working macro (sub) into one I can place in a cell? Such as SUM()???

  2. #2
    Guest

    Default

    You declare it as a Public Function. Instead of having it in a Sub, you would have it in a Public Function.

    for example, put this in a standard module:


    Public Function MySum(TgtRange As Range) As Long

    Dim Rng As Range
    Dim TempAns As Long

    For Each Rng In TgtRange
    TempAns = TempAns + Rng.Value
    Next

    MySum = TempAns

    End Function


    To use this function simply type in "=MySum(XX:XX)", where "XX:XX" is the range that you'd like to get the sum of.

    HTH

  3. #3
    Guest

    Default

    Man, is my face red! THANKS...

    (is there a way to set when these functions are activated? I am monitoring the length of a table for a %, can I set it so it will run when the table length cahnges-- or is that not needed?)

    Again Thanks for the help...

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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