Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excel lovers,
I have an Excel program with user forms containing many textboxes that people want to change values in by manipulating them in an algebraic fashion without reaching for their calculators or leaving the user form or the textbox involved. 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. -- Dennis Eisen Private Sub MyUserForm.MyTextBox_AfterUpdate() Dim ResultString as String Algebra MyUserForm.MyTextBox.Text, ResultString MyUserForm.MyTextBox.Text = ResultString 'Code goes here that reformats MyTextBox.Text with $ signs or % signs, etc, End Sub Sub Algebra(InputString As String, OutputString As String) Dim Fox As String, Char As String, Foxx As String Fox = InputString If InStr(Fox, "+") 0 Or InStr(Fox, "*") 0 Or InStr(Fox, "-") 0 Or InStr(Fox, "/") 0 Then L = Lenx(Fox) 'gets length of string Foxx = "" For i = 1 To L Char = Midx(Fox, i, 1) 'gets ith character If Not (Char = "$" Or Char = "%" Or Char = ",") Then Foxx = Foxx + Char End If Next i OutputString = Evaluate(Foxx) Else OutputString = Fox End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Stop a Procedure from another procedure | Excel Discussion (Misc queries) | |||
What is more efficient | Excel Discussion (Misc queries) | |||
Which is more efficient? | Excel Programming | |||
Efficient Looping | Excel Programming |