PC Review


Reply
Thread Tools Rate Thread

changing math operations for math operations with = sign

 
 
filo666
Guest
Posts: n/a
 
      3rd Mar 2008
I have this code:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim arr() As Variant
On Error GoTo eh
Application.EnableEvents = False
For cnt1 = 1 To target.value.words.count
arr(cnt1) = Target.Value.words(cnt1)
If IsNumeric(arr(cnt1)) Or arr(cnt1) <> "+" Or arr(cnt1) <> "-" Or arr(cnt1)
<> "*" Or arr(cnt1) <> "/" Or arr(cnt1) <> "^" Or arr(cnt1) <> "." Then
GoTo eh
End If
wrdd = wrdd + arr(cnt1)
Next
Target.Value = "=" & wrdd
eh:
Application.EnableEvents = True
End Sub

what I want to do is if the user types 3+5 then excell will change 3+5 to
=3+5 and will solve the operation; the problem us that
target.value.words.count
and Target.Value.words(cnt1) dont exist in excel, any suggestion
thanks

 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      3rd Mar 2008
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target
Set r = Range("B9")
If Intersect(t, r) Is Nothing Then Exit Sub
Application.EnableEvents = False
t.Value = Evaluate("=" & t.Value)
Application.EnableEvents = True
End Sub
--
Gary''s Student - gsnu200771


"filo666" wrote:

> I have this code:
>
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
> Dim arr() As Variant
> On Error GoTo eh
> Application.EnableEvents = False
> For cnt1 = 1 To target.value.words.count
> arr(cnt1) = Target.Value.words(cnt1)
> If IsNumeric(arr(cnt1)) Or arr(cnt1) <> "+" Or arr(cnt1) <> "-" Or arr(cnt1)
> <> "*" Or arr(cnt1) <> "/" Or arr(cnt1) <> "^" Or arr(cnt1) <> "." Then
> GoTo eh
> End If
> wrdd = wrdd + arr(cnt1)
> Next
> Target.Value = "=" & wrdd
> eh:
> Application.EnableEvents = True
> End Sub
>
> what I want to do is if the user types 3+5 then excell will change 3+5 to
> =3+5 and will solve the operation; the problem us that
> target.value.words.count
> and Target.Value.words(cnt1) dont exist in excel, any suggestion
> thanks
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Mar 2008
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim arr() As Variant
Dim LastPlace As Long
Dim i As Long

On Error GoTo eh
Application.EnableEvents = False

With Target

LastPlace = 1

For i = 1 To Len(.Value)

If Not (IsError(Application.Match(Mid$(.Value, i, 1), Array("+",
"-", "*", "/", "^", "<>"), 0))) Then

If i > 1 Then

If IsNumeric(Mid$(.Value, LastPlace, i - LastPlace))
Then

LastPlace = i + 1
Else

Exit For
End If
End If
End If
Next i

If i > Len(.Value) Then

If IsNumeric(Mid$(.Value, LastPlace, i - LastPlace)) Then

.Formula = "=" & .Value
End If
End If
End With
eh:
Application.EnableEvents = True
End Sub



--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"filo666" <(E-Mail Removed)> wrote in message
news:13A1D507-BD88-4791-80B2-(E-Mail Removed)...
>I have this code:
>
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
> Range)
> Dim arr() As Variant
> On Error GoTo eh
> Application.EnableEvents = False
> For cnt1 = 1 To target.value.words.count
> arr(cnt1) = Target.Value.words(cnt1)
> If IsNumeric(arr(cnt1)) Or arr(cnt1) <> "+" Or arr(cnt1) <> "-" Or
> arr(cnt1)
> <> "*" Or arr(cnt1) <> "/" Or arr(cnt1) <> "^" Or arr(cnt1) <> "." Then
> GoTo eh
> End If
> wrdd = wrdd + arr(cnt1)
> Next
> Target.Value = "=" & wrdd
> eh:
> Application.EnableEvents = True
> End Sub
>
> what I want to do is if the user types 3+5 then excell will change 3+5 to
> =3+5 and will solve the operation; the problem us that
> target.value.words.count
> and Target.Value.words(cnt1) dont exist in excel, any suggestion
> thanks
>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      3rd Mar 2008
Watch the wrap

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim arr() As Variant
Dim LastPlace As Long
Dim i As Long

On Error GoTo eh
Application.EnableEvents = False

With Target

LastPlace = 1

For i = 1 To Len(.Value)

If Not (IsError(Application.Match(Mid$(.Value, i, 1), _
Array("+", "-", "*", "/", "^", "<>"), 0))) Then

If i > 1 Then

If IsNumeric(Mid$( _
.Value, LastPlace, i - LastPlace)) Then

LastPlace = i + 1
Else

Exit For
End If
End If
End If
Next i

If i > Len(.Value) Then

If IsNumeric(Mid$(.Value, LastPlace, i - LastPlace)) Then

.Formula = "=" & .Value
End If
End If
End With
eh:
Application.EnableEvents = True
End Sub


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Bob Phillips" <(E-Mail Removed)> wrote in message
news:eX%(E-Mail Removed)...
> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
> Range)
> Dim arr() As Variant
> Dim LastPlace As Long
> Dim i As Long
>
> On Error GoTo eh
> Application.EnableEvents = False
>
> With Target
>
> LastPlace = 1
>
> For i = 1 To Len(.Value)
>
> If Not (IsError(Application.Match(Mid$(.Value, i, 1),
> Array("+", "-", "*", "/", "^", "<>"), 0))) Then
>
> If i > 1 Then
>
> If IsNumeric(Mid$(.Value, LastPlace, i - LastPlace))
> Then
>
> LastPlace = i + 1
> Else
>
> Exit For
> End If
> End If
> End If
> Next i
>
> If i > Len(.Value) Then
>
> If IsNumeric(Mid$(.Value, LastPlace, i - LastPlace)) Then
>
> .Formula = "=" & .Value
> End If
> End If
> End With
> eh:
> Application.EnableEvents = True
> End Sub
>
>
>
> --
> ---
> HTH
>
> Bob
>
>
> (there's no email, no snail mail, but somewhere should be gmail in my
> addy)
>
>
>
> "filo666" <(E-Mail Removed)> wrote in message
> news:13A1D507-BD88-4791-80B2-(E-Mail Removed)...
>>I have this code:
>>
>> Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
>> Range)
>> Dim arr() As Variant
>> On Error GoTo eh
>> Application.EnableEvents = False
>> For cnt1 = 1 To target.value.words.count
>> arr(cnt1) = Target.Value.words(cnt1)
>> If IsNumeric(arr(cnt1)) Or arr(cnt1) <> "+" Or arr(cnt1) <> "-" Or
>> arr(cnt1)
>> <> "*" Or arr(cnt1) <> "/" Or arr(cnt1) <> "^" Or arr(cnt1) <> "." Then
>> GoTo eh
>> End If
>> wrdd = wrdd + arr(cnt1)
>> Next
>> Target.Value = "=" & wrdd
>> eh:
>> Application.EnableEvents = True
>> End Sub
>>
>> what I want to do is if the user types 3+5 then excell will change 3+5 to
>> =3+5 and will solve the operation; the problem us that
>> target.value.words.count
>> and Target.Value.words(cnt1) dont exist in excel, any suggestion
>> thanks
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is the (math) division sign in MS Word? =?Utf-8?B?b3V0ZXJtb3N0?= Microsoft Word Document Management 11 21st May 2008 02:14 PM
I want to remove these: > (looks like a greater than sign in math) Chad Harris Microsoft Word New Users 8 10th Apr 2008 12:52 AM
Math class for Visual Basic.NET (matrix operations) Ing. Carlos Villaseņor M. Microsoft VB .NET 10 30th Oct 2006 09:24 PM
How Math.Cos & Math.Sin is implemented? Morgan Cheng Microsoft C# .NET 13 17th Oct 2006 04:03 AM
excel math forumla? (simple math problem inside for math people!) Jason Microsoft Excel Discussion 3 16th Feb 2006 10:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:02 PM.