LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Can this procedure be made more efficient?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop a Procedure from another procedure Ayo Excel Discussion (Misc queries) 1 October 30th 08 01:42 AM
What is more efficient Brad Excel Discussion (Misc queries) 2 November 20th 06 09:13 PM
Which is more efficient? Norm[_5_] Excel Programming 3 April 2nd 04 04:24 PM
Efficient Looping tehwa[_9_] Excel Programming 3 February 2nd 04 04:44 AM


All times are GMT +1. The time now is 08:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"