Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a string that contains math problems with numbers and operators. I
need to assign the solution to a variable. See examples below. My first thought was to use split with "+" as my delimiter. Worked great! Problem is that the string can have any combination of +, -, *, and / operators or no operators at all. Anyone have a suggestion? Examples: String ; Result "15" ; 15 "10+5" ; 15 "20-5" ; 15 "10+7-2" ; 15 "30/3+5" ; 15 "-5+20" ; 15 Notice the minus sign in the last example. If a minus sign is the first character then the first number is negative. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Evaluate it
?evaluate(activecell.value) in the immediate window or MsgBox evaluate(activecell.value) -- HTH Bob Phillips "crazybass2" wrote in message ... I have a string that contains math problems with numbers and operators. I need to assign the solution to a variable. See examples below. My first thought was to use split with "+" as my delimiter. Worked great! Problem is that the string can have any combination of +, -, *, and / operators or no operators at all. Anyone have a suggestion? Examples: String ; Result "15" ; 15 "10+5" ; 15 "20-5" ; 15 "10+7-2" ; 15 "30/3+5" ; 15 "-5+20" ; 15 Notice the minus sign in the last example. If a minus sign is the first character then the first number is negative. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My God! Was it really that simple? I can't believe it. Thanks so much Bob
for your response. Not only do I have my fix, but I have a new method under my belt as well. Thanks, Mike "Bob Phillips" wrote: Evaluate it ?evaluate(activecell.value) in the immediate window or MsgBox evaluate(activecell.value) -- HTH Bob Phillips "crazybass2" wrote in message ... I have a string that contains math problems with numbers and operators. I need to assign the solution to a variable. See examples below. My first thought was to use split with "+" as my delimiter. Worked great! Problem is that the string can have any combination of +, -, *, and / operators or no operators at all. Anyone have a suggestion? Examples: String ; Result "15" ; 15 "10+5" ; 15 "20-5" ; 15 "10+7-2" ; 15 "30/3+5" ; 15 "-5+20" ; 15 Notice the minus sign in the last example. If a minus sign is the first character then the first number is negative. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Mike,
As Tom points out, Evaluate can be used for any valid formula, like ?evaluate("cos(45)/sin(23)^3") -- HTH Bob Phillips "crazybass2" wrote in message ... My God! Was it really that simple? I can't believe it. Thanks so much Bob for your response. Not only do I have my fix, but I have a new method under my belt as well. Thanks, Mike "Bob Phillips" wrote: Evaluate it ?evaluate(activecell.value) in the immediate window or MsgBox evaluate(activecell.value) -- HTH Bob Phillips "crazybass2" wrote in message ... I have a string that contains math problems with numbers and operators. I need to assign the solution to a variable. See examples below. My first thought was to use split with "+" as my delimiter. Worked great! Problem is that the string can have any combination of +, -, *, and / operators or no operators at all. Anyone have a suggestion? Examples: String ; Result "15" ; 15 "10+5" ; 15 "20-5" ; 15 "10+7-2" ; 15 "30/3+5" ; 15 "-5+20" ; 15 Notice the minus sign in the last example. If a minus sign is the first character then the first number is negative. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Demo'd from the immediate window:
sStr = "30/3+5" ? evaluate(sStr) 15 -- Regards, Tom Ogilvy "crazybass2" wrote in message ... I have a string that contains math problems with numbers and operators. I need to assign the solution to a variable. See examples below. My first thought was to use split with "+" as my delimiter. Worked great! Problem is that the string can have any combination of +, -, *, and / operators or no operators at all. Anyone have a suggestion? Examples: String ; Result "15" ; 15 "10+5" ; 15 "20-5" ; 15 "10+7-2" ; 15 "30/3+5" ; 15 "-5+20" ; 15 Notice the minus sign in the last example. If a minus sign is the first character then the first number is negative. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Just to elaborate - any valid Excel formula:
sStr = "cos(45)/sin(23)^3" ? evaluate(sStr) -0.866912172733401 -- Regards, Tom Ogilvy "crazybass2" wrote in message ... I have a string that contains math problems with numbers and operators. I need to assign the solution to a variable. See examples below. My first thought was to use split with "+" as my delimiter. Worked great! Problem is that the string can have any combination of +, -, *, and / operators or no operators at all. Anyone have a suggestion? Examples: String ; Result "15" ; 15 "10+5" ; 15 "20-5" ; 15 "10+7-2" ; 15 "30/3+5" ; 15 "-5+20" ; 15 Notice the minus sign in the last example. If a minus sign is the first character then the first number is negative. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
and for your specific point
sStr = "-5+20" ? evaluate(sStr) 15 -- Regards, Tom Ogilvy "crazybass2" wrote in message ... I have a string that contains math problems with numbers and operators. I need to assign the solution to a variable. See examples below. My first thought was to use split with "+" as my delimiter. Worked great! Problem is that the string can have any combination of +, -, *, and / operators or no operators at all. Anyone have a suggestion? Examples: String ; Result "15" ; 15 "10+5" ; 15 "20-5" ; 15 "10+7-2" ; 15 "30/3+5" ; 15 "-5+20" ; 15 Notice the minus sign in the last example. If a minus sign is the first character then the first number is negative. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Formula Help - Split capital letters from first part of string | Excel Discussion (Misc queries) | |||
Split text string using mid-search? | Excel Discussion (Misc queries) | |||
extract text from string, leaving numbers and operators | Excel Discussion (Misc queries) | |||
split string based on a SET of words | Excel Discussion (Misc queries) | |||
Excel 2000 VBA - Using Split() with no Lelimiter in string | Excel Programming |