Attachment 357212
Hi Guys
I’m after some direction on this one.
I want the user to be able to amend code by changing a cell in the worksheet without the need to edit the code.
Background
I have the attached file which creates a 100 x 100 grid of x and y coordinates and using a hardcoded function determines the z coordinate for each x and y and then plots a 3 dimensional image representing that function. At present it just makes pretty images (try it for yourself) and one day I may actually find a practical use for it.
For the example attached I use a 2 dimensional array for z and calculate as follows:
z(x, y) = (x - 50) ^ 3 + 50000 * Sin((y - 50) / 4)
The (x-50) and (y-50) are simply to ensure the 100 x 100 grid is centred around x=0 and y= 0 axis.
If I want to plot a different function I need to edit this line of the code.
I would like to be able to enter in a cell (say y3)in the worksheet a similar function say x^2 + y^2 and have the code adjust accordingly, but attempts to set z(x,y) = range(“y3”).value simply sets z(x,y) to a string value equal to “x^2 + y^2” rather than amending the line of code. Once I work this out I can use simple substitution formula’s to change the x’s and y’s back to (x-50) and (y-50) so I’m not too concerned about that at present.
Is there a way to take the text string from a cell and use this in the code? If so how do I do it
WARNING
I’m self taught in VBA so my code might be a bit messy
Please Login or Register to view this content.
Bookmarks