ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   BEDMAS (https://www.excelbanter.com/excel-worksheet-functions/140085-bedmas.html)

[email protected]

BEDMAS
 
Hi All,

I'm trying to create a spreadsheet that will generate an assignment
for my students on the use of "BEDMAS" - order of operations. I plan
to print it out and give it to them, and that part is working fine. I
am having trouble getting Excel to take the data and calculate it. I
know it's possible, but I just can't get it to work. :-)

Here's what I've got in cells (for example):

A B C D E F G H I J K L M N

a) ( 4 "" * "" 2 ) - "" 7 "" = ______
b) "" 3 "" + ( 4 "" * "" 8 ) = ______

I've managed to concatenate b through L so that it reads (4*2)-7, but
I can't find a way to get Excel to actually compute that answer. Is
there anyone out there that has any ideas?

Thanks in advance for your help!

Dave


Dave Peterson

BEDMAS
 
You're going to need some VBA. Is that ok?

If it is, you could use a UDF like:

Option Explicit
Function Eval(rng As Range) As Variant

Dim myCell As Range
Dim myStr As String
Dim Res As Variant

myStr = ""
For Each myCell In rng.Cells
myStr = myStr & myCell.Value & " "
Next myCell

Res = Application.Evaluate(myStr)

If IsError(Res) Then
Eval = "Error!"
Else
Eval = Res
End If

End Function

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:N1)




wrote:

Hi All,

I'm trying to create a spreadsheet that will generate an assignment
for my students on the use of "BEDMAS" - order of operations. I plan
to print it out and give it to them, and that part is working fine. I
am having trouble getting Excel to take the data and calculate it. I
know it's possible, but I just can't get it to work. :-)

Here's what I've got in cells (for example):

A B C D E F G H I J K L M N

a) ( 4 "" * "" 2 ) - "" 7 "" = ______
b) "" 3 "" + ( 4 "" * "" 8 ) = ______

I've managed to concatenate b through L so that it reads (4*2)-7, but
I can't find a way to get Excel to actually compute that answer. Is
there anyone out there that has any ideas?

Thanks in advance for your help!

Dave


--

Dave Peterson


All times are GMT +1. The time now is 12:35 AM.

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