Converting sting to variable

  • Hello everyone,

    I am working on a vba code.


    I have a function in terms of x, say (x)^2 + x.

    I want to find values of this function for different values of x, say from 1 to 5.

    For that I am using a 'for next' loop.

    Example,

    For x = 1 To 5

    fx(x,1) = (x)^2 + x

    Next x


    But problem is that, this is not the only function. I want these values for any other functions of 'x', say cos(x), etc.

    And I want this function to be given by a user as a sting in terms of 'x' either as an input in a cell or as input in inputbox and then I want to use this in 'for next' loop.

    This is like converting a string to function with variable as 'x'.


    Please help me. How to do this.

    Thank you in advance.

  • Hi,


    Your question is a little bit confusing ...


    But it reminds me of a very elegant solution developed, a long time ago, by Jan Karel Pieterse


    Attached is a test file to chart an equation


    Hope this will help

  • Hello,


    Hope file was not corrupted ... there is no macro in this file ... only named ranges ...


    You should also review your Excel options in the trust center ...

  • I don't want to plot the values of the function.

    I am assigning these values to arrays and doing further operations on them.

    I think the question is clear now.

  • here is the actual code that I am working on


    and the code continues..

  • Please read the Forum Rules to understand how the Forum works and why I have added Code Tags to your post


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.Be sure to use them in future posts.


    How to use code tags

    Note: no apostrophe in the tags, just used for demonstration here.

    ['code]


    your code goes between these tags


    ['/code]


    Or, just highlight all of the code and press the <> in the post menu above button to add the code tags.


    Thanks.

  • Carim

    I opened your excel file, but is not helpful to me.

    You are welcome


    The interest of this specific example is the use of EVALUATE ... :)

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Smiley" icon, below, in the bottom right corner :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!