terra incognita A broad view of Microsoft Office


27
Jul/10
0

How it’s Made: Tower Defense - a Game in Excel 2010

This post is syndicated from Microsoft Excel 2010.

image

 

This blog post is brought to you by Karen Cheng a Program Manager on the Excel team.

 

 

In today's post, we'll show you how the arcade game Tower Defense was created in an Excel spreadsheet (see a video of the game being played here).  In this game, creeps move toward your castle. You must defend it by placing towers which shoot at the creeps. The more creeps you kill, the more money you get to buy and upgrade your towers.

To play, you'll need -

· To download the game here.

· To install Excel 2010, hot off the press last week. You can get a free trial here. The games use features that are new to Excel 2010, so they won't work in older versions.

When you open the file to play, don't forget to enable the macros. Also, if you get a circular reference warning, you need to enable iterative calc by setting “Enable iterative Calculation” in advanced options under File -> Options -> Formulas -> Enable Iterative Calculations.

clip_image001

Instructions and General Gameplay

After selecting your level and difficulty and clicking Play, the game begins.

Creeps - Creeps come in "waves" of four. Each wave, they get stronger - They require stronger bullets to kill (strength), move faster (speed), and reward you with more cash once killed (worth). These stats are under the Creeps part of the menu.

clip_image003

Towers - To buy a tower, click on one of the towers on the right and then click on the map to place it. Towers come in two varieties - Basic and Advanced. Advanced towers are basically supercharged versions of the basic towers that shoot stronger bullets (Strength), faster bullets (Speed), and bullets that travel farther (Range). Clicking on a tower will show you these stats. Since a tower can only fire one bullet at a time, hitting the creeps at a closer range lets the tower shoot more bullets before the creep gets too far away. Range is shown by a heat map around the tower.

clip_image005

When you earn enough cash, you can upgrade your towers, which will increase their stats. Upgraded towers are represented by blue shading.

clip_image007

Lives - If a creep reaches your castle (which is represented by the flag), you lose a life. You get three lives.

The Graphics Engine

Play the game and you'll notice the animation of the creeps and bullets. You wouldn't be able to achieve this level of smooth animation if each cell simply represented a pixel, as in Missile Command. So how was this done?

Creeps and Bullets

The secret lies in a transparent scatter chart (two charts, technically, but that's more detail than we'll get into) that lays on top of the game screen. The creeps and bullets are points on the scatter plot, which constantly recalculates and refreshes. The bullets are represented by one series on the chart (the Xs) and the creeps are represented by a second series (the red diamonds).

The X-Y coordinates of the creeps and bullets are calculated via linear interpolation based on a number of factors (the map path, the location of the castle, and game's clock).

I won't go specifically into what each of these columns mean, but here's a peek into some of the stats used to calculate the position of the creeps. They are on the hidden worksheet, Calc.

clip_image009

Map Path, Towers, and Castles

The map path, towers, and castles are all drawn on the grid with conditional formatting. Below I've overlaid an image of the numbers behind the cells with the game area. Below  you can see that -1 represents the map path, -23 is a basic tower with two upgrades, etc. These numbers are constantly being recalculated as you play the game.

clip_image010

clip_image011

The conditional formatting rules behind the grid

In Excel 2010, we've expanded your capability to create intricate and complex rules by allowing formula-based conditional formatting to reference other worksheets. Behind each cell is a formula that looks something like this:

=IF(Calc!B263<>0,Calc!B263,IF(AND('Fixed Data'!AE2=Calc!$D$6,'Fixed Data'!AE16=Calc!$C$5),0,('Fixed Data'!AE2-Calc!$D$46)^2+('Fixed Data'!AE16-Calc!$D$45)^2))

While we won't go into what every piece of that formula does, we do want to draw attention to the references to two hidden worksheets, Fixed Data and Calc - cross-sheet references made possible in Excel 2010. If you're curious, unhide the sheets and check out the formulas behind the cells. The ones that generate the heat map of tower strength on mouse hover are the most interesting. Finally putting that Pythagorean Theorem you learned back in grade school to good use!

Bells and Whistles

Sparklines

When you play the game, you'll notice an animated line at the bottom, which displays the frame rate of the game. This is done with sparklines, a new feature in Excel 2010 that allows you to embed mini charts in a cell.

clip_image012

While sparklines weren't exactly designed to be animated, they can be animated with some clever spreadsheet engineering. The sparkline is based on a data range (Calc worksheet, C56:C85) which is constantly recalculated, creating the illusion of movement.

Slicers

Did you notice that when you chose the level and difficulty at the beginning of the game, you didn't have to go to a dropdown to do it? Instead you clicked on buttons in slicers, a new feature in Excel 2010 that allows you to quickly and visually interact with your data.

Oh, and of course - no game would be legitimate without being available in multiple languages.

clip_image013

A final note

One cool thing about this spreadsheet is how little macros were used. For the most part, macros are only being used to start/stop the game and keep track of mouse movements and clicks. Everything else is pure Excel: the calculation engine, conditional formatting, and two new features to Excel 2010 - sparklines and slicers.

20
May/10
0

10 Days for Office 2010 Series – Reviewing the Dow Jones Industrial in Excel 2010

This post is syndicated from Microsoft Excel 2010.

Today’s post was written by Excel MVP Nate Oliver.

Excel 2010 presents traditional numerical analysts with new and old tools; today we’ll explore two of them. The difference is that the first shall be what we call qualitative, and the second, quantitative.

As a real-world example, on a really hot day, qualitative could mean hot, while quantitative could mean 100F. We shall explore both, with Excel 2010, with respect to the Dow Jones Industrial Average (DJIA).

Read more here...

22
Apr/10
0

Conditional Formatting Rules Simplified

This post is syndicated from Microsoft Excel 2010.

imageThanks to Amit Velingkar for writing this blog post.

Conditional formatting is a popular feature and is a great way to easily identify cells with a range that meet some criteria. However, users often want to create conditional formatting rules that go beyond comparing a cell’s value to a single value or a single cell reference - row or column comparisons are commonly requested operations. In this blog post, we will learn how to use relative references in conditional formatting rules to make such tasks easier.

For example, consider the spreadsheet below where we have sales data for different branches of an organization over the years 2005 to 2009:

image

Let’s say we want to highlight the cells where sales have decreased compared to the previous year. By default, conditional formatting inserts an absolute reference when we select another cell as a reference. (ExcellsFun has a great video that explains relative and absolute cell references). When absolute references are used in conditional formatting rules, every cell to which the conditional formatting rule is applied is compared to that single referenced cell.

 

Tedious Way – Lots Individual Conditional Formatting Rules

For complex conditional formatting rules, users often get around that problem by creating lots of individual rules applied to single cells. In our example, we select cell C2 and click on “Conditional Formatting -> Highlight Cell Rules -> Less Than” on the home tab. When the Less Than dialog pops up, we select the cell B2 against which we want to compare. Notice that the value is the dialog gets replaced by an absolute reference to cell B2 ($B$2).

image

To perform column comparisons in this fashion, the user ends up having to create a new rule for each cell and select the neighboring cell for comparison.

image

This small table consists of as many as 20 individual rules - each comparing the cell’s value to its neighbor on the left. Besides being a tedious task (users often automate such tasks by using subroutines), there are other problems with this approach:

- Performance hit: Having lots of individual conditional formatting rules can degrade performance.

- Difficult to Maintain: Such rules are hard to maintain. Besides having to edit multiple rules for any changes, the rules won’t adjust if you insert a new row or column.

 

Relative References – using a single Conditional Formatting Rule

There is an easier way to do this by using just one Conditional Formatting Rule applied to the entire range. To do this, select the entire range of cells to which you want to apply the rule (in our example: C2:F6) and click on “Conditional Formatting -> Highlight Cell Rules -> Less Than” on the home tab. When the Less Than dialog pops up, we again select the cell B2 to get an absolute reference ($B$2). However, this time we use change the reference to be a relative reference (B2).

TIP: you can use the F4 key to cycle through different types of relative references until you get B2 without the $ signs.

And there you have it; we have just one Conditional Formatting rules where every cell’s value is compared. We get exactly, the same result as before. And there’s more, the rules automatically adjust to if new rows are added in the middle of this range. For example, let us add information about a new branch in Boston.

image

image

 

How Relative References work in CF Rules?

In conditional formatting rules, cell references are relative to the top-left most cell in the Applies to range. To simplify things, I like to pretend as if I have only selected the top-left most cell and I am writing a formula in that particular cell. In our case, the top-left cell C2 was compared against the cell to its left (B2). Hence, all the other cells in the range were compared with the cell to their left.

The diagrams below are examples of how to setup two commonly used CF rules – row and column comparisons. The cells with blue borders indicate the range to which this CF rule is applied, the bold blue border is used to illustrate the top-left most cell in the CF range and the red border shows the cell referenced by the CF formula. The black arrow indicates the direct relationship between the top-left cell and the cell reference, while the gray arrows indicate the implied relationships that are formed as a result.


imageimage

You can always verify this by using the Conditional Formatting Rules Manager (select any cell within this range and clicking on the “Conditional Formatting -> Manage Rules” on the home tab) as shown below:

 

image

Also, you can toggle between the different types of relative references to compare against a particular column or a particular row. Relative references can also be used inside formulas to create complex Conditional Formatting rules.

Summary

Anytime you need to conditional formatting using complex cell comparisons, consider using relative references to make things easier. Remember, rules are relative to the top-left most cell in the Applies To range. I would love to hear more feedback on Conditional Formatting and ideas that you might have for future versions of Excel.

22
Apr/10
0

Conditional Formatting Rules Simplified

This post is syndicated from Microsoft Excel 2010.

imageThanks to Amit Velingkar for writing this blog post.

Conditional formatting is a popular feature and is a great way to easily identify cells with a range that meet some criteria. However, users often want to create conditional formatting rules that go beyond comparing a cell’s value to a single value or a single cell reference - row or column comparisons are commonly requested operations. In this blog post, we will learn how to use relative references in conditional formatting rules to make such tasks easier.

For example, consider the spreadsheet below where we have sales data for different branches of an organization over the years 2005 to 2009:

image

Let’s say we want to highlight the cells where sales have decreased compared to the previous year. By default, conditional formatting inserts an absolute reference when we select another cell as a reference. (ExcellsFun has a great video that explains relative and absolute cell references). When absolute references are used in conditional formatting rules, every cell to which the conditional formatting rule is applied is compared to that single referenced cell.

 

Tedious Way – Lots Individual Conditional Formatting Rules

For complex conditional formatting rules, users often get around that problem by creating lots of individual rules applied to single cells. In our example, we select cell C2 and click on “Conditional Formatting -> Highlight Cell Rules -> Less Than” on the home tab. When the Less Than dialog pops up, we select the cell B2 against which we want to compare. Notice that the value is the dialog gets replaced by an absolute reference to cell B2 ($B$2).

image

To perform column comparisons in this fashion, the user ends up having to create a new rule for each cell and select the neighboring cell for comparison.

image

This small table consists of as many as 20 individual rules - each comparing the cell’s value to its neighbor on the left. Besides being a tedious task (users often automate such tasks by using subroutines), there are other problems with this approach:

- Performance hit: Having lots of individual conditional formatting rules can degrade performance.

- Difficult to Maintain: Such rules are hard to maintain. Besides having to edit multiple rules for any changes, the rules won’t adjust if you insert a new row or column.

 

Relative References – using a single Conditional Formatting Rule

There is an easier way to do this by using just one Conditional Formatting Rule applied to the entire range. To do this, select the entire range of cells to which you want to apply the rule (in our example: C2:F6) and click on “Conditional Formatting -> Highlight Cell Rules -> Less Than” on the home tab. When the Less Than dialog pops up, we again select the cell B2 to get an absolute reference ($B$2). However, this time we use change the reference to be a relative reference (B2).

TIP: you can use the F4 key to cycle through different types of relative references until you get B2 without the $ signs.

And there you have it; we have just one Conditional Formatting rules where every cell’s value is compared. We get exactly, the same result as before. And there’s more, the rules automatically adjust to if new rows are added in the middle of this range. For example, let us add information about a new branch in Boston.

image

image

 

How Relative References work in CF Rules?

In conditional formatting rules, cell references are relative to the top-left most cell in the Applies to range. To simplify things, I like to pretend as if I have only selected the top-left most cell and I am writing a formula in that particular cell. In our case, the top-left cell C2 was compared against the cell to its left (B2). Hence, all the other cells in the range were compared with the cell to their left.

The diagrams below are examples of how to setup two commonly used CF rules – row and column comparisons. The cells with blue borders indicate the range to which this CF rule is applied, the bold blue border is used to illustrate the top-left most cell in the CF range and the red border shows the cell referenced by the CF formula. The black arrow indicates the direct relationship between the top-left cell and the cell reference, while the gray arrows indicate the implied relationships that are formed as a result.


imageimage

You can always verify this by using the Conditional Formatting Rules Manager (select any cell within this range and clicking on the “Conditional Formatting -> Manage Rules” on the home tab) as shown below:

 

image

Also, you can toggle between the different types of relative references to compare against a particular column or a particular row. Relative references can also be used inside formulas to create complex Conditional Formatting rules.

Summary

Anytime you need to conditional formatting using complex cell comparisons, consider using relative references to make things easier. Remember, rules are relative to the top-left most cell in the Applies To range. I would love to hear more feedback on Conditional Formatting and ideas that you might have for future versions of Excel.

3
Sep/09
0

Hidden gems in Excel 2007, part 2: Give your lists some bounce and shine

This post is syndicated from Inside Office Online blog.

(This article first appeared as an Office Hours column ) Last week I introduced you to J.P. Bagel, one of our serious Excel experts, and showed you one of his tips: How to see ALL the tabs of your many worksheets — a particularly good tip for complex...(read more)
13
Aug/09
0

The DisplayFormat OM

This post is syndicated from Microsoft Excel.

New features in conditional formatting extend to the object model as well. Excel has traditionally allowed users to access the formatting of their cells through the object model. For example, Users can use the interior class which lives off the range object to access the formatting of the cell. Selection.Interior.Color returns the background color of the cell.

However, Selection.Interior.Color does not take into account the conditional formatting applied to the cell.  In Excel 2010, we’ve introduced a new class called DisplayFormat which lives off the range object.  This class provides an easy way to access the formatting applied by conditional formatting rules and other things like table styles that format the cells but don't really reflect it in the cell formatting properties today.

For example, the following code gets the fill color of the active cell (after taking into account any conditional formatting applied to the cell):

Selection.DisplayFormat.Interior.Color

Let us consider a simple example as to how the DisplayFormat object might be used.  A bookstore provides bonuses to its employees based on how well they have met their sales targets for the year. The bonuses are awarded as follows:

  • 15% bonus – Sales targets have been met for each quarter for the year.
  • 5% bonus – Sales target was met for at least one quarter during the year.
  • No Bonus – Failed to meet even a single sales target.

At the start of each year, the bookstore compiles a sales target for each employee as follows:

image

Then, the bookstore records the actual sales on a separate worksheet and uses conditional formatting to highlight quarters where the employees failed to meet their sales target.  These quarters are highlighted with a red background as follows:

image

Since the bonuses awarded at the end of the year depend on how well the salespeople met their targets, you can imagine that a formula to compute the bonus percentage would be quite complex.  Using the new DisplayFormat object, you can easily write custom user defined functions that leverage the smartness in conditional formatting rules to compute the bonuses.

In this case, the function to compute the employee bonuses looks as follows:

Function BonusAward(quarters As Range) As Double

Dim iBelowTarget As Integer ' Number of cells below target

' initialize variables

BonusAward = 0.15 'default 15% bonus-met target for all qtrs

iBelowTarget = 0

' loop through each cell

For Each qCell In quarters

'if conditional formatting cell background is NOT red(255)

If qCell.DisplayFormat.interior.color > 255 Then

  BonusAward = 0.05 ' award less bonus (failed quarter)

  iBelowTarget = iBelowTarget + 1

End If

Next qCell

' Award zero bonus if all quarters were below target

If iBelowTarget = quarters.Cells.count Then BonusAward = 0

End Function

The DisplayFormat object will provide access to conditional formatting results using many existing classes and properties such as the Borders, Characters, Font, Interior and Style.  Since we use existing classes and properties, it means that you can easily extend your existing code to work with it.

This wraps up my series of posts on conditional formatting. In our next Excel 2010 post we’ll continue on the theme of data visualization improvements by discussing some things we did with charts.

11
Aug/09
0

More Conditional Formatting Features in Excel 2010

This post is syndicated from Microsoft Excel.

In this blog post I’ll walk through some of the new Conditional Formatting features in Excel 2010 such as:

  • Cross-Sheet References
  • Robust Error Handling
  • Performance Enhancements

Cross-Sheet References

In Excel 2010, you can create conditional formatting with references to a different sheet on the workbook. This means that you no longer need to copy or link your data to the same sheet when using conditional formatting.

For Example, let us look at the monthly sales data for a bookstore chain. The bookstore organizes their sales data as follows:

  • Each location gets its own worksheet
  • The last worksheet contains the cumulative company wide sales figures with the averages for each department.

We will apply conditional formatting so that we can easily determine if the department at the local branch is doing better or worse as compared to the other branches in the company. Let us use the San Francisco branch as our example. We will apply a green background fill for the departments if they are performing better than average.

1.  Start on the sheet for San Francisco location and select the cells in the sales column to which you want to apply conditional formatting. Go to the Home Tab-> Conditional formatting -> Highlight Cell Rules -> Greater Than.

image

2.  Click on the clip_image001 (RefEdit icon) and simply navigate to the sheet whose value you want to compare against. In our case, we will navigate to the company wide worksheet and click on the average for the first row in the department column.

image

3.  Now here is a neat little tip – references in Conditional Formatting follow all the rules of absolute and relative references. The Cell References are relative to the active cell in the “Applies To” range (in this case the top-left cell in the range).

Let us modify the reference to be relative to the rows by deleting “$” symbol before the row number.

image

The result is that each department on the “San Francisco” sheet being compared to the same type of department on the “Company” sheet.

4.  Click OK and you have a Conditional Formatting Rule that is dependent on other sheets in the workbook.

image

Error Handling

Have you ever used ranged based conditional formatting (such as icon sets, color scales and data bars) only to find that one of your formulas have evaluated to an error?  In Excel 2007, errors in the range would lead to conditional formatting not being applied to all the cells in the range.  Users told us that this was frustrating.

In Excel 2010, conditional formatting silently ignores the errors and continues applying conditional formatting to the rest of the cells in the range.

image

Performance Enhancements

For this release we’ve also improved the performance of formatting in Excel 2010. For conditional formatting we store dependencies of the formulas used so we don’t need to reevaluate the entire conditional format as often. We’ve also made banding in the table and pivot table styles faster, so this will impact things like refreshing a pivot table or scrolling with a large table on your sheet. For all the above cases, we also cache the format of the cell so if you scroll off the screen and come back, or switch sheets and come back, we’ll remember the cell formatting and can display faster.

In our next Excel 2010 post, we’ll look at a new object model feature for conditional formatting.

7
Aug/09
0

Data Bar Improvements in Excel 2010

This post is syndicated from Microsoft Excel.

Data Bars are a popular type of conditional formatting that was introduced in Excel 2007. The basic idea of data bars is that Excel draws a bar in each cell whose length corresponds to the value of the cell relative to the other cells in the selected range. Data bars are a great way of seeing trends in your data.

In our example, we have the historical Sales and Profit amounts for a fictional bookstore. The last column has the percentage of increase in profits when compared to the previous year. We have applied Excel 2007 data bars to some of these columns. In the example below, we can see that sales rose in early 2000’s and are decrease for the past few years.

image

However, the data in the above example has several nuances which are hard to spot in Excel 2007. In Excel 2010, we have made several improvements to data bars which make them an even better choice for your data analysis. We shall look at data bar improvements in Excel 2010 and how these improvements help you get more information from your data.

Proportional Data Bar Lengths

In our example above, we can see that the sales rose from 1999 to the early 2000’s and have fallen since then for the past few years. While this is good information, Excel 2007 does not provide a good indication of how much the sales have increased or decreased during that period. The sales amount was $210,374.88 in 1997 and they rose to $271,884.86 in 2004. Thus, sales in 1997 were about 78% of the sales in 2004.

However if someone would try to compare the lengths of the data bars, they might be fooled into thinking that sales rose by about 5 times during that period or 500% (since the length of the data bar corresponding to year 2004 is about 5 times the length of data bar corresponding to year 1997).

Why does this happen in Excel 2007? By default, Excel assigns the shortest data bar to the lowest value in the range and the longest data bar to the highest value in the range. All other data bars are assigned a length in between according to their values.
image

In Excel 2010, data bars are now drawn proportionally according to their values. Using our example, the following table describes the behavior in detail:

  Excel 2007 Excel 2010
Minimum default value

- Lowest Value in Range

- Occupies 10% of cell width

- Automatic (Minimum of zero or lowest negative value in range)

- Occupies 0% cell width (not drawn)

Maximum default value

- Highest Value in Range

- Occupies 90% of cell width

- Automatic (Maximum of zero or highest positive value in range)

- Occupies 100% cell width (entire cell)

Key observation - Data bars cannot be used to compare values. - Proportional data bars lets you compare values.
Example - Users may incorrectly feel that sales increased 5 times from 1997 to 2004. - The 1997 sales are about 78% of the 2004 sales.
Screen shot image image

Formatting Options – Solid Fills and Borders

We received a lot of feedback from users that it was hard to see the ends of your data bars since we used a gradient fill to color data bars. Gradient fill has the advantage that it makes the text values in the cells easier to see. However as in our example above, it is hard to see which cell has the highest sales value (answer: 2004).

Taking the limitations of gradient fill into account - we introduced new formatting options, such as borders and solids fills, for data bars in Excel 2010:

Formatting Styles

Gradient Fill

(Excel 2007 & Excel 2010)

Gradient Fill with Borders

(Excel 2010)

Solid Fill

(Excel 2010)

Advantage

- Easy to see text

- Easy to see data bar edges

- Easy to see text

- Prominently see data bars

Disadvantage

- Hard to see edges of data bars

- Borders may overlap some text

- Harder to see text (depending on color)

Example

- Difficult to see which year (2003, 2004 or 2005) has the highest sales amount.

- Text is easily visible for each cell.

- Easy to see that 2004 has the highest sales.

- In year 2001, the edge of the data bar overlaps the last digit “8” making it harder to read.

- Easy to see that 2004 has the highest sales.

- In year 1998, some portion of the text is on green background and the remainder is on the white background making it harder to read.

Screen Shot

clip_image001

clip_image002

clip_image003

Note: Formatting options only affect the visual look of the data bar and does not change the behavior of data bar in any way.

Negative Value Data Bars

Looking at the “profit increase” column, each year can be categorized into two types:

  • Profit Growth: years where profits increased from the previous year.
  • Profit Decline: years where profits fell when compared to the previous year.

However in Excel 2007, data bars do not make any distinction between the positive and negative values making it hard to see the difference.

In Excel 2010, we have introduced negative value data bars which can help analyze trends when negative values are involved. By default, we smartly position the axis in the cell so that a small negative value will not occupy half the cell lengths when bigger positives values are also in the range. If you prefer, we let you position the axis in the center of the cell.

Excel 2007

Excel 2010

Key Observation

- Hard to see different between positive and negative values

- Easily highlight negative values

Example

- It is hard to see here that in years 2006 to 2007 we are seeing substantial drop in profits.

- We can easily observe the large drop in profits from 2006 to 2008.

Screen Shot

clip_image001[5]

clip_image002[5]

To Summarize, Excel 2010 allows you to see more trends with your data bars with the following new features:

  • Proportional data bar lengths
  • Negative data bars
  • customize formatting of your data bars:
    • Choose between Gradient and Solid fill style
    • Apply borders to data bars
    • Change fill / border colors for both positive and negative value data bars.

We would love to hear from you about data bars and what you think about these new features in Excel 2010.