Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Neil
 
Posts: n/a
Default Converting cell contents to a formula

I have a list of quantites in one cell "D4"
"D4" = 6/6 3/2.6 5/1.2.
I need to sum each of these to a total so I use the following formula
=SUBSTITUTE(SUBSTITUTE(TRIM(D4),"/","*")," ","+")
Result: "6*6+3*2.6+5*1.2"
How can I convert the result to a formula that would show the sum 49.8

Thanks for any help.


  #2   Report Post  
Biff
 
Posts: n/a
Default

Hi!

You can't "build" a formula like that although it is possible to calculate
the resulting TEXT string but the formula needed to do that would be a mile
long and EXTREMELY difficult to maintain.

So, I have to ask, why are you wanting to do this? Why not put the values in
separate cells?

Biff

"Neil" wrote in message
...
I have a list of quantites in one cell "D4"
"D4" = 6/6 3/2.6 5/1.2.
I need to sum each of these to a total so I use the following formula
=SUBSTITUTE(SUBSTITUTE(TRIM(D4),"/","*")," ","+")
Result: "6*6+3*2.6+5*1.2"
How can I convert the result to a formula that would show the sum 49.8

Thanks for any help.



  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

You're gonna need some VBA to evaluate the expression.

Option Explicit
Function Eval(myStr As String) As Variant
Eval = Application.Evaluate(myStr)
End Function


Then you'd use:

=eval(SUBSTITUTE(SUBSTITUTE(TRIM(D4),"/","*")," ","+"))
in your cell.

You could do the substitutes in code, too. But then you couldn't use your
=eval() without those substitutions.

Option Explicit
Function Eval(myStr As String) As Variant
With Application
Eval = .Evaluate(.Substitute _
(.Substitute(.Trim(myStr), "/", "*"), " ", "+"))
End With
End Function

Then you'd use:
=eval(d4)

In either case...

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=eval(a1)


Neil wrote:

I have a list of quantites in one cell "D4"
"D4" = 6/6 3/2.6 5/1.2.
I need to sum each of these to a total so I use the following formula
=SUBSTITUTE(SUBSTITUTE(TRIM(D4),"/","*")," ","+")
Result: "6*6+3*2.6+5*1.2"
How can I convert the result to a formula that would show the sum 49.8

Thanks for any help.


--

Dave Peterson
  #4   Report Post  
Neil
 
Posts: n/a
Default

Thanks for your reply Biff
Dave has given a solution using VBA.
I was thinking along your lines.
The spreadsheet is a copy of how quantity surveyors are used to noting their
material lists
it would be messy if they needed to insert an unknown number of extra rows
as the number of various lengths varies.
"Biff" wrote in message
...
Hi!

You can't "build" a formula like that although it is possible to calculate
the resulting TEXT string but the formula needed to do that would be a
mile long and EXTREMELY difficult to maintain.

So, I have to ask, why are you wanting to do this? Why not put the values
in separate cells?

Biff

"Neil" wrote in message
...
I have a list of quantites in one cell "D4"
"D4" = 6/6 3/2.6 5/1.2.
I need to sum each of these to a total so I use the following formula
=SUBSTITUTE(SUBSTITUTE(TRIM(D4),"/","*")," ","+")
Result: "6*6+3*2.6+5*1.2"
How can I convert the result to a formula that would show the sum 49.8

Thanks for any help.





  #5   Report Post  
Neil
 
Posts: n/a
Default

Thanks Dave
That will work fine.
"Dave Peterson" wrote in message
...
You're gonna need some VBA to evaluate the expression.

Option Explicit
Function Eval(myStr As String) As Variant
Eval = Application.Evaluate(myStr)
End Function


Then you'd use:

=eval(SUBSTITUTE(SUBSTITUTE(TRIM(D4),"/","*")," ","+"))
in your cell.

You could do the substitutes in code, too. But then you couldn't use your
=eval() without those substitutions.

Option Explicit
Function Eval(myStr As String) As Variant
With Application
Eval = .Evaluate(.Substitute _
(.Substitute(.Trim(myStr), "/", "*"), " ",
"+"))
End With
End Function

Then you'd use:
=eval(d4)

In either case...

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=eval(a1)


Neil wrote:

I have a list of quantites in one cell "D4"
"D4" = 6/6 3/2.6 5/1.2.
I need to sum each of these to a total so I use the following formula
=SUBSTITUTE(SUBSTITUTE(TRIM(D4),"/","*")," ","+")
Result: "6*6+3*2.6+5*1.2"
How can I convert the result to a formula that would show the sum 49.8

Thanks for any help.


--

Dave Peterson



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
Can a Formula in Cell X modify Cell Y? alMandragor Excel Discussion (Misc queries) 7 February 10th 05 09:51 PM
looking for a formula Amanda Excel Worksheet Functions 5 January 5th 05 07:37 AM
How do I add a date formula to a cell but hide the contents with . Emzy Wemzy Excel Discussion (Misc queries) 2 December 12th 04 01:48 PM
How can I write an if-then formula for 0 or less than 0 in cell t. Baz1 Excel Worksheet Functions 1 November 30th 04 04:33 PM
How do I do math on a cell name in formula? Mark Mulik Excel Worksheet Functions 3 November 23rd 04 03:43 PM


All times are GMT +1. The time now is 08:28 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"