Spreadsheet Design

Spreadsheet functional programming

In his recent paper Spreadsheet functional programming, Dave Wakeling discussed the idea of using a functional programming language from within a spread sheet.

It’s an interesting approach, because the implementation effetely allows you to write code (in this case Haskell) in cell comments, in such a way that the results are computed on the fly – i.e. not complied.

As you might expect, there are a number of issues with the implementation from a practical stand point, but that’s not what I’m interested in here – I want to talk about the concept of functional programming in relation to spread sheets, which this paper also focuses on.

It’s my view that a spreadsheet is a functional programming language. This means that I have an issue with the goal of the paper, which is:

“Our hope is that by doing so, we might get spreadsheet programmers to give functional programming a try”

Nothing wrong with that, but my views that spread sheet users already are functional programmers!!! So why them might we want to use Haskell with Excel? Towards the end of the paper Wakeling suggest some possible strengths to this approach.

1. It uses an ordinary spreadsheet. The functionality of, experience with, and Support for a familiar product all carry over.

2.  It uses an ordinary functional language. The benefits of such languages also carry over. (Backus, 1978; Turner, 1982; Hughes, 1989).

3. It can accommodate any pace of change. The old way of doing things can coexist with the new one.

Unfortunately I don’t agree that these are real benefits. Oh dear! – Why?

1. This is a case for anything that  integrates with Excel; the benefit is independent of what it is that’s being integrated.  This is the benefit of using a spread sheet and a programming language over using a programming language on it own.  It’s tenuous to claim it as a strength.

2. The benefits are true of Functional v’s Imperative programming languages (lasy, high order functions). Since Excel functions operate in a very similar way to functional programming these benefits don’t really exists between Excel worksheet functions and a functional programming language.

3. This statement is true of any situation where the 2 technologies can co-exist you could say the same about using C, VSTO etc, etc, again it’s really tenuous to claim it as a strength of any like for like approach.

So if these strengths are not in fact all that real, then why would we want to use a functional programming langue with spreadsheets? Perhaps a clue is given in this passage:

“On the positive side, many everyday programming errors are detected that would otherwise lead to incorrect results, including dangling cell references, undefined functions, and functions with the wrong type of arguments.”

I can see how using a more “strongly typed” language could possibly help reduced type errors, not sure how undefined functions would be helped or how “dangling cell references” (in fact, I don’t know what this means at all) would be effected.  Generally further discussion and justification of the benefits of using a functional language with a spreadsheet are needed to build a case for doing so.

The paper did not convince me that using a functional language has any really benefits to using worksheet functions or any other programming language. Having said that, the paper does show that its possible to link technologies like this and it’s another interesting approach to programming spreadsheets. The prospect of F# and XLDNA and F# in VSTA/O are also interesting things to start thinking about!  The application of functional programming languages within spreadsheets is interesting  and Wakeling should be congratulated for opening up the debate for future discussion– as hopefully this post will do too!

Unit testing Excel VBA – xlUnit demo

Back in February I did a podcast with Mike Woodhouse, based around testing VBA code. Mike has written a unit testing frame work for VBA code, called xlUnit. Over the last few weeks I’ve been using xlUnit to help write a generic validation class for VBA, so I thought I would put together a little video of how the addin can be used to write tests for your code.

Its in 2 parts because you can only upload videos that are 10 minutes long to you tube.  The first part is the basics and in the second part I show some examples from my project.

You can find out more about xlUnit at Mikes blog, grumpy old programer:

The MIE Podcasts – Chandoo

Purna Duggirala. Purna Duggirala. Purna Duggirala. You might better know him as Chandoo, but his name is Purna Duggirala. Chandoo is a very friendly fellow, and we had a great chat about charts and dashboards, how to design them what approaches to take etc etc… So if that sounds like your sort of thing, have a listen.

The PHD company christmas card circa 2009......

Purna runs a great Excel site Pointy Haired Dilbert, it really is super, but I reckon that anyone who reads this will know that much already. He has an MBA from IIM Indore and Computer Science degree from Andhra University, and he’s an Excel MVP, of course!  only the best for the readers (and listeners) of Methods In Excel.

One thing I didn’t know about Purna is his ability to multi task, the bat eared amongst you will be able to detect Chandoo simultaneously talking and typing away… no doubt writing some more excellent blog posts for PHD!

Excel Workbook Size Reduction Revisited.

Back in January I posted a few ideas to reduce workbook size. This post got quite a few comments, so I’d thought I’d write them up into a proper post.

Also Gorden has noticed a strange thing happening, so I wanted to highlight that a bit better too.

Here is a check list!

  • Zip the file!
  • Used Range see here.
  • Removing any VBA code
  • Remove Formatting.
  • Use Rob Bovey’s code clearer
  • Duplicate pivotcaches (ethoros)
  • Excel Filter Ranges (Gordon)
  • Embedded Pictures  (Jon von der Heyden)
  • XL 2007, Store as .xlsb  (sam)
  • VlookUps, External data (Charlie Hall)

Please check back in the original post for explanations of these if they don’t make sense.

And here the one Gordon recently found, which is the odd one! What do you make of it?

I recently found a method that can reduce the file size of an Excel file containing significant amounts of VBA, sometimes by as much as 50%.

  1. Note file size
  2. Open file but do not enable VBA/macros
  3. Make no changes
  4. Save & close file
  5. Check file size again

Even after using Rob Bovey’s Code Cleaner this can sometimes make a huge difference to the size of the file. Many of the workbooks I manage are read-only and reside on a network share somewhere, and as this can make these files much smaller (1300KB down to 700KB etc.) it improves load times, particularly over VPN connections, resulting in an improved user experience.

The files work exactly the same after this is carried out and although I’ve done some examination to see what might have changed I’ve not managed to find anything. Most likely some internal decrofting* is responsible, but I’ve really no idea why this works.

I’ve just tried this on a file and it went form 7.2 megs to 6.6 megs, not bad for doing nothing.

I cant think what it would be that causing this, maybe P-code compilation or something?

* decrofting, some sort of Scottish thing. Crofting is small scale land sharing for framing, so decrofting must be the un sharing of land… or something!

Excel Workbook Size Reduction

As you work and work on a spreadsheet it has a tendency to grow in size. This is caused by adding more data, formulas and charts etc, but as file size grows workbooks can become unstable. I’m not sure what the current thinking is, but workbooks over 100mb always used to worry me. I know some folks will have bigger ones that are stable, but it’s just a rough guide.

Anyway it turns out that it’s not only the data, formulas and charts that effect work book size, but other, possibly less obvious things too.

Luckily there are some steps we can take to help reduce workbook size, making them more stable and reducing the file size on disk – think e-mail.

The effect will differ massively depending on the workbook you start with, but for illustration, this shows what happen to a workbook after applying each method in isolation.

What are the options?

  • Zip the file – and remember if you’re trying to get the file under a certain size, maybe to get it through a corporate firewall, other zip applications are about, which can give smaller file sizes than the built in windows one.
  • Used Range – Clearing up the used range means that empty cell don’t get sotred in the file, Excel is not great at clearing up it’s owe file structure, good news is its easy to fix, see here.
  • Removing any VBA code from the file can help reduce the file size – it’s not always possible, but if it is, maybe you could try it! Also watch out of userform with massive graphic files embed in them – classic!
  • Remove Formatting. Having lots of complex formatting is a key driver for file size, removing unnecessary or overly complex formatting can drastically reduce the size of you files.
  • Rob Bovey’s code clearer, strips out VBA models can re imports them, this can help clean them up – if you been working on a bit VBA project, this can help – big time!

So there you go, a few ideas about how to reduce file size, maybe these will help someone.