Writing a formula into VBE

Alexxu

Board Regular
Joined
Aug 9, 2008
Messages
134
Hello.
My problem is how to write a formula in vb.
I searched everywhere, and nothing
I write a code, but i get overflow error.
Rich (BB code):
Option Explicit
Const Pi = 3.14159265358979
Const B = 2
Const C = 1.5
Const D = 8
Const E = 4


Private Sub chkRezultat_Click()
 Dim X As Single, Y As Single, Z As Single, W As Single
 
    txtRezultat.Visible = True
 
  'here i type the formula
   X = B * Val(txtQT.Text)
   Y = B * (Pi) ^ C
   Z = Val(txtsigmax.Text) * Val(txtsigmay.Text) * Val(txtsigmaz.Text)
   W = X * Y
   txtRezultat.Text = Val(W) / Val(Z)

'here is how the formula should look like   
'txtRezultat.Text = ((B * Val(txtQT.Text)) / Val((B * Pi) ^ C)) * Val(txtsigmax.Text) *Val (txtsigmay.Text) * Val(txtsigmaz.Text)
   
  chkRezultat.Value = False
 
End Sub
When it gets overflow these turns yellow:
Rich (BB code):
 txtRezultat.Text = Val(W) / Val(Z)
I don't know if this:
Rich (BB code):
Dim X As Single, Y As Single, Z As Single, W As Single
, is written correctly.
Any idea or suggestion?
Thanks.
My real formula looks like this(is one of the tree formula that i have to write)
Cmax (X) = 2*QT/((2*π)^3/2)*σx*σy*σz
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Alex

I really can't follow what you want to do.:eek:

And you appear to be working with a userform or worksheet controls, which might have been useful to tell us.:)

As to the overflow error, I can only hazard a guess is that it's because some value, probably a divisor, is zero.

PS There is a worksheet function PI(), and you could access it in VBA like this.
Code:
    MsgBox Application.WorksheetFunction.Pi
 
Upvote 0
Why are you using Val as a matter of interest?
 
Upvote 0
I have a userform with 4 textboxes(txtQT, txtsigmax, txtsigmay, txtsigmaz) and another textbox in which i see the result(txtResult), which is triggered by a checkbox.
The formula that i want to write in the vb is: 2*QT/((2*π)^3/2)*σxyz
I typed some constants:
Code:
Option Explicit
Const Pi = 3.14159265358979
Const B = 2
Const C = 1.5 '(3/2)
Then all i wanted was to write the formula(i don't want to connect her to the worksheet), in the vbe.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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