How to calculate convert string into formula and calculate in vb

wedelia

New Member
Joined
Sep 27, 2007
Messages
12
Hi all,

I'm setting up a spreadsheet at the moment and would like to offer the users to input the equation (for example: "=(Log10((delta / 324.33) ^ (1 / -0.0451)))") that was derived from other sources in Excel.

*delta is a range of values

I'm trying to get vb to get the equation and calculate using the equation for different delta values.

What I have done is:

Static Function XXValue(byVal delta As Single, byVal Type As String)

Dim UserEquation As String
Dim UserDefinedEqn As Single

If Type = "user-defined" Then

UserEquation = Range("UserdefinedEqn").Value
'UserdefinedEqn is the name for cell containing the equation that user has input

CalculatedEqn = Evaluate(UserEquation)

If CalculatedEqn > 2 Then
No = CalculatedEqn
If Calculated Eqn > Range("Limit").Value Then
'Limit the name for cell containing the limit of the calculation
No = Range("Limit").Value
End If

Number = 10 ^ No

End If

XXValue = Number

End Function

Not sure where I have gone wrong in this set of code. It doesn't seem to calculate at all. Could someone please offer some advice?

Thanks!
 
Hi,

I think I know what's wrong. I have placed the code in under Microsoft Excel Object > Sheet1 (Sheet1) instead of a module. That's why I keep getting the error.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top