View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Melanie Breden Melanie Breden is offline
external usenet poster
 
Posts: 88
Default Can this procedure be made more efficient?

Hi Dennis,

DennisE wrote:

The textboxes contain formatted text such as $2,345,678.50 and to ease
the burden of increasing the value by 15%, and/or dividing it in half, and/or
adding or subtracting $12,456, I've written the brute force procedure below
that centers around the Evaluate() method. That way a user could replace the
value
shown by 1.15*($2,345,678.50 + 12456)/2 without a calculator or resorting
to an intermediate spreadsheet, and when done with that variable quickly
move on to the next textbox, etc.

Any suggestions in the way of making the procedure "tighter" or
an alternate approach would be welcome.


use a Function instead of a Sub:

Private Sub MyTextBox_AfterUpdate()
MyTextBox.Text = Algebra(MyTextBox.Text)
End Sub

Function Algebra(InputString As String) As String
Algebra = InputString
If InputString Like "*[+*-/]*" Then
InputString = Replace(InputString, "$", "")
InputString = Replace(InputString, "%", "")
InputString = Replace(InputString, ",", "")
Algebra = Evaluate(InputString)
End If
End Function

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)