ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User entry correction (https://www.excelbanter.com/excel-programming/340082-user-entry-correction.html)

Ali Baba

User entry correction
 
Hi

I have a userform with a textbox to enter a formula. The user is required
to enter a formula as in the following examples

X1+3*X
5+X1
X1+X2-10*X3+4

and so on

I want to make sure that the user enters the correct format. This would
include:
1 €“ enter only X values
2 €“ X are in upper case
3 - asterix between the number and X (eg 5*X1)

This is what I have done so far

--------------------------------------------------------------------------------------
Dim PointToX As Single, PointToAsterix As Single

StrFunction = txtFunction.Text
StrFunction = Replace(StrFunction, "x", "X")
StrFunction = Replace(StrFunction, " ", "")
PointToX = InStr(1, StrFunction, "X") 'First "X" occurrence
If PointToX = 0 Then
GoTo FunctionInputError
Else

FunctionInputError:
txtFunction.Text.SetFocus
txtFunction.Text.SelStart = 1
txtFunction.Text.SelLength = Len(txtFunction.Text)
Exit Sub

End Sub


Any help??


Ali Baba

User entry correction
 
I FORGOT TO SAY THAT THE USER MAY ALSO ENTER IN THIS FORM

X1*X2+3*X2*X4


All times are GMT +1. The time now is 09:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com