Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate a formula in a textbox

Status
Not open for further replies.

bpeirson

Technical User
Sep 28, 2005
85
CA
I have a form with several textboxes. This form is used to streamline a process originally done directly in a worksheet. For the most part it is working well.

The part I don't like is when working on a worksheet I could enter a formula directly into a cell to get a number. How can I enter a formula into a textbox and have it convert that into a number for me. I don't need special functions, just "+", "-", "*" and "/". The use of "(" and ")" would be cool as well but not required.

The reason I would like this is because I don't know how much 41" of 4" std pipe weighs but I do know that 1' weighs 10.79 lbs. Therefore weight = 41/12*10.79. I find typing this into the cell quicker than looking for my calculator.
 
Something like this ?
SomeCell.Formula = "=" & yourTextBox.Text
MsgBox "Result=" & SomeCell.Value

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Great solution. I added a roundup function so the returned value won't overfill the textbox (ie 1/3)

Code:
Cells(x, 1).Formula = "=Roundup(" & weight.text & ",2)"
weight.Value = Cells(x, 1).Value
 
You can calculate directly:

weight.Text = Application.WorksheetFunction.RoundUp(Application.Evaluate(weight.Text), 2)

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top