+ Reply to Thread
Results 1 to 10 of 10

Function returning worksheet formula problem.

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    sweden
    MS-Off Ver
    Excel 2007
    Posts
    9

    Function returning worksheet formula problem.

    Please Login or Register  to view this content.
    Hello!
    As i wrote this pain in the *** to change formula i figured it would be better to use a custom function to use it.
    It goes beyond my VBA-skills to translate the entire formula to VBA code so instead i figured i would have a vba function returning a formula but where the dates were already filled in (when you use the function)
    Now, i only get the cell returned as a "string". The Cell shows the formula i want (with Sdate and Edate instead of the chosen cells) as string. The formula of the cell is still mycustomfunction.

    Is there a way for the function to change the formula of the cell from which it was called?

  2. #2
    Registered User
    Join Date
    08-09-2012
    Location
    sweden
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Function returning worksheet formula problem.

    2014-01-29 8.jpg
    Like so.

  3. #3
    Registered User
    Join Date
    08-09-2012
    Location
    sweden
    MS-Off Ver
    Excel 2007
    Posts
    9

    Can a custom function alter the formula of its own cell?

    Hello, I'm stuck with a problem.
    Can a custom function alter the formula of its own cell?

    So for example
    Please Login or Register  to view this content.
    I cannot manage to change the calling cell with a VBA script. Im not talking about returning a value but to replace the cell formula.

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Can a custom function alter the formula of its own cell?

    Please confirm on which cell you are applying the UDF?

    Activecell refers to which cell?


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  5. #5
    Registered User
    Join Date
    08-09-2012
    Location
    sweden
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Can a custom function alter the formula of its own cell?

    Ah, Sorry about that This one is just an example to simplify my problem. But Lets say C2. So i want to add a formula in C2 to be "=test". And then i want the function itself to alter the formula of c2 so that it becomes "=A*B" I am well aware you can just add two cells in the function and set test= A*B but thats not what i want. It might work in my example but for the real problem that would take me hours.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Can a custom function alter the formula of its own cell?

    Nope, a UDF called from a spreadsheet cell cannot do that. A Sub Procedure can do that kind of thing all day long, and if you tie it into a calculate event procedure, it can be executed with each calculate event.

    Perhaps if you explain this in more detail and why you want to approach it this way, we can suggest some alternatives (like using the INDIRECT() or OFFSET() functions or something else).
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Can a custom function alter the formula of its own cell?

    I think maybe you wish to use named formula? You may define name (like 'test') that refers to formula like =$A$1*$B$1 and then in cells you may use =test. If you change formula in the name, cells will calculate this new formula.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Function returning worksheet formula problem.

    Kind of a duplicate post by the same user (threads merged, so link removed)

    As mentioned in the other thread, this is something a UDF called from a spreadsheet cell cannot do. I will certainly agree with you that formulas like that, with multiple parentheses and multiple levels of nesting and multiple conditions are difficult to work with (and I usually just don't have the patience to unravel them). You suggest that your concern is with the ability to "change" the formula. Can you explain in more detail what you need to do with this formula? How do you need to be able to change it?
    Last edited by MrShorty; 01-30-2014 at 10:04 AM.

  9. #9
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Can a custom function alter the formula of its own cell?

    Sort of a duplicate post. Here's the OP's original post with the full function that he is trying to work with http://www.excelforum.com/excel-prog...a-problem.html

  10. #10
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Function returning worksheet formula problem.

    frikost

    Pls take some minutes and read Forum rules.

    Don't post duplicated threads. For this time-as there are replies to both of then-i merged the threads.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Problem with XIRR function returning #NUM!
    By Francois_Provost in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-06-2005, 03:05 AM
  2. [SOLVED] Problem with XIRR function returning #NUM!
    By Francois_Provost in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-06-2005, 02:05 AM
  3. [SOLVED] Problem with XIRR function returning #NUM!
    By Francois_Provost in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-06-2005, 01:05 AM
  4. [SOLVED] Problem with XIRR function returning #NUM!
    By Francois_Provost in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-06-2005, 12:05 AM
  5. [SOLVED] Problem with XIRR function returning #NUM!
    By Francois_Provost in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-05-2005, 10:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1