Happy Thanksgiving 2014

November 25th, 2014 by datapig No comments »

No posts this week, but here's a gift for you. I made a Thanksgiving GIF you can share with the kids. I used a bunch of Excel shapes to make a cozy Thanksgiving movie. Who says Excel doesn't appeal to kids?

.
thanksgiving
.

I'll be back next week. Enjoy your time off!

The Best Reviews on Amazon

November 21st, 2014 by datapig 1 comment »

Over at Amazon, you'll find the Samsung 105 inch 4K Ultra-HD Curved TV.

The price tag on this substantial purchase is $120,000.

.

If you're apprehensive about taking the leap on this purchase, rest assured.

It's getting some of the best reviews I've seen.

.

.

.

Check out all the reviews here.

.

.

 

 

 

 

Prevent Worksheet Delete without Workbook Protection

November 20th, 2014 by datapig 8 comments »

My friend Tim sent me a message yesterday asking:

"I would like to allow people to insert and re-order worksheets but not delete any. Is that possible?"

Searching all the forums, I found that this question comes up with some frequency. There seems to be a common need to prevent the deletion of a worksheet, but still give users the ability to change the structure of the workbook. Excel does have a Workbook Protection feature, but that feature doesn't give you many options when you protect a workbook. That is to say, you can't specify that you want to prevent one action, but not other actions. So you're stuck with either protecting the workbook structure or not.

.

The answer will have to come from VBA.

In my search, I discovered that Excel 2013 added a new Worksheet Event called BeforeDelete.


.

Wow. I hadn't noticed this event before.

Of course, the Microsoft help files are as useful as ever (sarcastic tone).

.

Judging by the utter lack of examples on how other folks are using this, I'm assuming this new addition to the Worksheet events has gone largely unnoticed by many of us.

.

Apparently, this event triggers when you attempt to delete any worksheet in your workbook. Unfortunately, this event does not come with a Cancel method. Meaning that when a user deletes a worksheet, this event triggers, but then Excel goes ahead and deletes the worksheet anyway. It seems that the purpose of this event is to do some action before the worksheet is delete – not give the developer an opportunity to cancel the delete. So with this event, you can do things like: log the time the worksheet was deleted, save the workbook before deleting the worksheet, send an email before worksheet is deleted, or anything else you can think of.

.

I decided to solve Tim's problem with this small bit of code in the Worksheet_BeforeDelete event. This code simply renames the worksheet, then creates a copy with the original name. So before the worksheet is deleted, you essentially create a copy of it. No matter how many times the user tries to delete the worksheet, it will always be there.

Private Sub Worksheet_BeforeDelete()

Dim MyName As String

'Capture the original worksheet name
MyName = ThisWorkbook.ActiveSheet.Name

'Rename the worksheet
ThisWorkbook.ActiveSheet.Name = Left(MyName, 30) + "#"

'Create a copy of the worksheet
ThisWorkbook.ActiveSheet.Copy _
After:=Sheets(ThisWorkbook.ActiveSheet.Index)

'Name the copy to the original name
ThisWorkbook.ActiveSheet.Name = MyName

End Sub

.

If you have Excel 2013, you can right-click on the worksheet you want protected, then select the View Code option. Then simply paste this code into the VBE. Note that you'll have to do this for every worksheet you don't want deleted.

.

For those of you with Excel 2010 or prior versions, you're basically out of luck. You don't have the BeforeDelete event available to you. In those version, you'd have to employ messy tricks to hide the Delete Commands from the interface. These require VBA and even some RibbonX customization that I'd rather not get into.

Update: Jan Karel Pieterse, observing that my technique will zap any formula pointing to the deleted worksheet, has provided an excellent solution that is far superior to the one I proposed here.

In a normal module, paste this code:

Sub UnprotectBook()
ThisWorkbook.Unprotect
End Sub

Then for every worksheet, right-click, select View Code, and then paste this:

Private Sub Worksheet_Deactivate()
ThisWorkbook.Protect , True
Application.OnTime Now, "UnprotectBook"
End Sub

And this works in any version of Excel! Thanks Jan Karel!

 

Feel free to comment and tell us if and how you're using the BeforeDelete event. Like I said, I've just now noticed it. I'd like to know how anyone else is using it.

Methods of Measuring the Skewness of Data

November 17th, 2014 by datapig 2 comments »

Skewness is essentially how data is clustered together within a dataset. Every dataset can have some gradient of three skew states: No Skew, Positive Skew and Negative Skew.

  • In some datasets, the values tend to cluster around the Mean (the Average). These datasets are said to have a Normal Distribution and no skew.
  • In some datasets, the values tend to cluster below the Mean, giving you a distribution with a "tail" that tapers toward higher values. These datasets are said to have a Positive Skew.
  • In some datasets, the values tend to cluster above the Mean, giving you a distribution with a "tail" that tapers toward Lower values. These datasets are said to have a Negative Skew.

.

Understanding the Skew of your dataset can help make sense of the statistics that come out of it. For example, if you knew that your data included extreme values that skew to the negative, it could help guide you in deciding whether you should anchor your analysis to the Average, Median, Inter-Quartile range, or some other key statistical value.

Today, I'd like to give you several quick methods for determining the skewness of data.

.

Method 1: Graph your Data

Visualizing your data can quickly show you how your data is skewed. Two excellent ways to see the skew of your data are to visualize your data with a Histogram chart or a Box Plot.

.

Histogram charts are essentially visual representations of the frequency distribution of your data. With a histogram chart, you can get a good sense of how your data is distributed. My good friend and charting guru Jon Peltier has several excellent tutorials on building histograms.

.

Box Plots are another useful way to visualize the distribution of data. These charts plot the Mean of your dataset then creates a "box" around the Mean using the Quartiles. This method essentially gives you a visual representation of the location of key statistical points. Using this visualization, you can quickly see where your data bunches up and where there are long tails. Again, Jon Peltier has an excellent post on how to create Box Plots in Excel.

.

Method 2: Calculate using the Mean Median and Mode

If you don't want to take the time to create a chart, you can use some of the simple statistical points to get a general sense of how the data skews.

Specifically, you can review the location relationship between the Mean, Median and Mode of your dataset. If you don't know:

  • Mean is the average of your dataset
  • Median is the central data value of your dataset
  • Mode is the value that has the highest frequency (occurs most often)

The idea is to use some simple comparison measures.

If the Mode, Median, and Mean are around the name number, your dataset has No Skew.

If the Mode is less than the Median and the Median is less than the Mean, your dataset has a Positive Skew.

If the Mode is greater than the Median and the Median is greater than the Mean, your dataset has a Negative Skew.

.

Method 3: Calculate using the Quartiles

Another easy way to mathematically get a sense of the skew is to compare the Quartiles in your dataset.

A quartile is essentially a division of data into four defined intervals based upon the values of the data and how they compare to the entire set. These intervals each contain 25% of the entire population. Values falling below 25% of all the data analyzed is said to be in the 1st quartile. Values falling between 25.1% and 50% are in the 2nd quartile. Values falling between 51% and 75% belong to the in the 3rd quartile. And the remaining values are allocated in the 4th quartile. Feel free to read my previous post on Quartiles  to get a detailed primer.
.

In a dataset that has No Skew, Quartile 3 minus Quartile 2 will be equal to Quartile 2 minus Quartile 1.

In a dataset that has Positive Skew, Quartile 3 minus Quartile 2 will be greater than Quartile 2 minus Quartile 1.

In a dataset that has Negative Skew, Quartile 3 minus Quartile 2 will be less than Quartile 2 minus Quartile 1.

.

Method 4: Use the standard Skew Calculation

You can also use the standard statistical calculation for Skew:

3*(MEAN – MEDIAN)/STANDARD DEVIATION

This calculation is used in statistics to get a quick glimpse at the Skewness of a dataset.

Just for reference:

  • Normally Distributed datasets have a Skew result of 0 (no skew).
  • Datasets with a Positive Skew result in a number greater than 0.
  • Datasets with a Negative Skew result in a number less than 0.

The closer the resulting Skew calculation is to 0, the more normal the distribution is.

Take the example below. You can see in cell Z21, 1.11 is the calculated Skew for the dataset in column W.

Since the Skew is greater than 0, this tells us that we have a Positively Skewed dataset.

The intensity of the Skew is determined by how far it is from 0. In this case, 1.11 tells us that our dataset has a fairly strong skew to the positive.

.

Method 5: Use Excel's SKEW function.

Some of you statistics nerds will point out that in the previous example, we calculated the Skew on only 11 data points. The standard statistical calculation seems to exaggerate the result of Skew when you're dealing with small sample sizes. A more robust measure of Skewness would take into account the number of observations. This is where Excel's SKEW function comes in.

.

Excel's SKEW function will give you a different answer from the statistical calculation shown in Method 4.

This is because Excel' Skew calculation accounts for the number of observations in the dataset.

Excel's SKEW function tells us that the dataset is indeed positively skewed (the result is greater than zero). But you'll notice that Excel tempers the intensity of the skew, showing a lower number than the standard statistical calculation (.08 vs 1.11).

.

Method 6: Use Excel's Descriptive Statistics Feature

You can use Excel's Descriptive Statistics feature to output key statistical data points from your dataset.

SKEW is one of the calculations that output.

If you're interested, here is a clean tutorial on Excel's Descriptive Statistics feature.


.

So which one of these methods are best? Well it depends on what you need to do and how much time you have. I would say that it's always best to visualize your dataset before working on it. I typically build a histogram of any dataset I have just to see the general makeup of the data. If you don't want to go through that rigmarole, and just want a general sense of the Skewness of your data, Excel's SKEW function is probably the easiest method.

.

I guess that's it then. I don't know about you, but all that math talk has made me hungry. I'm off to get to get a breakfast sandwich.

New Dashboard Templates from Chandoo

November 13th, 2014 by datapig 1 comment »

The ever creative Chandoo has just release a new offering in his treasure trove of Excel goodies. If you don't know Chandoo, he's an Excel MVP, father of twins, lover of tea with milk, and owner of one of the most popular Excel blogs today.

.

I call him can-do Chandoo. No matter what crazy idea you throw at him, he has a knack of making it work.

Need an example? How about an Excel Podcast?

A long time ago, I thought about doing an Excel podcast, but I figured talking about Excel would be too boring without seeing the tips and tricks. Yet, can-do Chandoo made it work. He's on his 25th episode and seems to be going strong. Like that brown kid on a boat with a tiger, he makes any challenge look easy.

.

Well, today Chandoo beats me at yet another idea I've been toying with for years: ready-to-use Dashboard Templates.

With his templates, you simply enter your data, set up few calculation options, decide how your dashboard should look, and poof – like magic, you have a dashboard that synthesizes your data into easy to consume insights.

.

I spent the better part of 3 hours dissecting his template and here are my thoughts:

  • Overall – very impressive. It does indeed do what you think it should do. I jammed some of my data into the dashboard, selected the view I wanted and it produced that view.
  • Having this template is like having an advanced mock-up tool. With this template, I can mock up all kinds of views for my clients. I may not use this as my final dashboard, but this template definitely saves loads of time putting together a straw-man to show to my clients.
  • No VBA! Given the very dynamic nature of the dashboard, it's hard to believe there is no VBA in it. Chandoo uses a whole host of tricks from Slicers to Named Ranges to keep the final dashboard VBA free. I think this is especially handy if your organization uses Office 365 or Excel Services on SharePoint. Why? You can publish your final dashboard to the web!

 

In fact, there are so many tricks used in this dashboard, you can learn all kinds of advanced techniques and best practices just by reverse-engineering the formulas and named ranges. I'll give you an example. In the set up page, you can define the number formatting for each of your metrics. This means you can change the format of a metric to (let's say) a percent with two decimal places. This immediately changes the dashboard to show the selected format.

My question was how the heck did he change the format based on a dropdown selection without VBA? The answer is he uses the TEXT Function to dynamically change formatting. This is a clever trick that I'll be using in my dashboard models. Small tricks like these make Chandoo's template worth more than the resulting dashboards themselves.

.

Ok. I'm starting to feel a little dirty.

Jeez - it sounds like I'm ready to take a shower with the guy.

.

The bottom line is that this new offering from Chandoo is pretty damned cool, no matter who you are.

Take a moment this week check it out.

Getting Rid of the Stubborn AutoFill Options Menu

November 6th, 2014 by datapig 4 comments »

Here's a bit of Excel trivia for you.

The other day, I was filling in a series of numbers (type in two numbers, select the two numbers, and then drag the fill handle down to fill a series), when I noticed something I hadn't paid attention to before. The Autofill Options menu (that icon you get when you fill a series) doesn't respond to any of the usual actions you would take to make something go away.

I pressed the Escape key.

It wouldn't go away.

I switched to another sheet and came back.

It wouldn't go away.

I pressed F2 and Esc.

I wouldn't go away.

.

Naturally, being the Excel nerd I am, I set out to experiment and list some of the actions that make this stubborn menu disappear.

  1. You can close your workbook then reopen it. Seriously? Not event an option.
  2. You can start typing anywhere in the sheet. This one seems obvious, but I don't like the idea of needing to type something just to make a menu disappear.
  3. You can zoom out then back in. I guess that's a bit better than typing, but it still seems like a waste. Why would I ever zoom to get rid of a menu?
  4. You can click in the formula bar. Easy enough. You still have to click in the formula bar then out again, but this option is better than zooming.
  5. The best option I've found is to click any of the lines between columns or rows. This is a quick one-click action. Simply hover your mouse over any of the lines separating column letters or row numbers, then click the mouse when your cursor turns into a cross.

.

It would be so much better if a simple press of the Escape key worked.

Anyway...time to do some real work.

Halloween and Dressing up your Charts

October 30th, 2014 by datapig No comments »

Tomorrow is Halloween here in America; a time for candy and costumes.

Unfortunately, Halloween falls on a work day. I hate that.

There is always peer pressure to participate in 'Halloween Costume Day'. What is Halloween costume day? It's a day where, in the name of fun, all employees are encouraged to dress up in a costume for the day. This means the people you normally hate are now working around you dressed as robots and witches.

.

Well if you're feeling pressure to dress up for Halloween, here are three simple costume ideas I pulled off the web. All of these are just the ticket for the lazy passive-aggressive employee in your life.

.

Identity Thief

Get some "Hello My Name Is" stickers and write a bunch of names on them. Then just stick them to your shirt to become an Identity Thief.

.

Error 404 Message

This idea has been around for some time. If you're completely lazy, you can take a white T-shirt and become an Error 404 message.

.

50 Shades of Grey

If you want to be a bit more provocative, get some color samples from your local hardware store and create a 50 Shades of Grey costume.

.

.

Using Paste Special Chart Formats

Speaking of dressing up, here's a quick trick that lets you dress up your unformatted charts.

After you've expertly formatted a chart, you probably want to apply that same format to other charts.

Instead of doing all that work again, you can use the Paste Special Formats option on your unformatted charts.

.

Step 1: Select your formatted chart and press Ctrl+C on your keyboard

Step 2: Select your unformatted chart, click the Paste dropdown on the Home tab, and then select Paste Special.

.

Step 3: On the Paste Special dialog box, select the Formats option and then click OK.

.

 

If all went well, your unformatted chart will be all dressed up and ready to go.

Repeat these steps for all your charts.

.

Happy Halloween!

Add a DropBox Account to your Office 2013 Save As Screen

October 27th, 2014 by datapig 4 comments »

I use DropBox for many of the things I do: I pass files to clients, I collaborate with co-authors on books, and I store documents I want to keep in the cloud. For the better part of a year, I was managing my DropBox documents via their website. I finally did a little research and found a way to add my DropBox account to my Save As Screen in Office 2013.

.

If you use DropBox, I highly recommend this nifty trick.

.

Step 1: Download and Install the DropBox Application

This will create a new DropBox directory (typically C:\Users\YourUserName\DropBox)

 

.Step 2: Download and Run the DropBox Batch File

DropBox offers a .bat file that will automatically adjust your registry (only for Windows 7 and higher) to add DropBox as cloud option in Office 2013. Download this .bat file to your machine and then double-click it to run. When you run it, you'll see a command prompt asking you for the location of your DropBox directory. Simply type or paste the full path then press enter.

.

Once you get positive confirmation that the script ran successfully, close the command prompt window.

 

.Step 3: Add a new Storage Location

At this point you can open any Office 2013 application and click the Add a Place option. From here, simply select the DropBox option. This action adds the DropBox location to all your Office applications.

.

 

I wouldn't say it saves me loads of time, but it's definitely nicer to stay in the Office environment even when I'm managing my DropBox account.

Hack into Password Protected VBA Projects

October 8th, 2014 by datapig 19 comments »

A few days ago, I had to pull out one of my old tricks to hack into a password protected VBA module. The file I was working on was protected by a former (evil) employee who, for some reason, did not leave the VBA password.

.

I'm notoriously lazy, so there is no way I'm retyping code that's already there. I'd rather hack into the workbook.

.

Today, I'll walk you through the steps I use to crack VBA passwords. I learned this trick a while back from one of my Excel Boot Camp students. I can't remember who. Sorry…whoever you are. Even though I can't remember your name, I value our friendship greatly. » Read more: Hack into Password Protected VBA Projects

5 Rarely Used VBA Tricks

October 1st, 2014 by datapig 12 comments »

Hey folks! I'm back from a long hiatus. I've been down with (of all things) the Shingles. I know…weird. Apparently, if you've had the chicken pox as a child (which I did) there is a chance that the dormant virus causing chicken pox can rear its ugly head and develop into Shingles. It's actually fairly rare in men my age to get Shingles.

.

So in celebration of my recent recovery from my rare Shingles outbreak, I'll share with you a few rarely used VBA tricks. » Read more: 5 Rarely Used VBA Tricks