Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default changing math operations for math operations with = sign

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default changing math operations for math operations with = sign

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default changing math operations for math operations with = sign

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" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default changing math operations for math operations with = sign

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" wrote in message
...
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" wrote in message
...
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
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
bitwise operations as in xor stevenshrii Excel Discussion (Misc queries) 2 April 16th 09 09:43 AM
IF Calculation and Operations Rich Excel Discussion (Misc queries) 3 February 3rd 09 10:37 PM
OWC operations in Excel mondayisgreat Excel Discussion (Misc queries) 0 March 3rd 06 03:07 PM
Repeating VBA operations Adam1 Chicago Excel Discussion (Misc queries) 3 March 1st 05 07:05 PM
VBA for matrix operations Jules[_3_] Excel Programming 1 September 24th 03 02:14 AM


All times are GMT +1. The time now is 04:31 AM.

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

About Us

"It's about Microsoft Excel"