10 May 2009 by Ross McLean
The response to my blog post “Request an Excel blog post” was not stellar! But 2 people did request things. XL Dennis (aka Dennis Wallentin) asked about Tables in Excel 2007, and Sam had some interest in function performance.
I did a quick video about tables in Excel 2007, which I need to compliment with one about how to use the new referencing system too, but that’s for another day.
Sam was kind enough to send me some work he’s done around function execution speeds. Sam used the MIE calculation tool to help him time these functions – good stuff!
The workbook is here, and the findings might make more sense when you see them in the worksheet ;-)
In Sam’s own words, here’s what he found out:
The — version of sumproduct is faster than the other two
Dsum – Sum is faster than Sumproduct and for Excel 2003 and below should be the most preferred way of summarising data
For 2007 – Sumifs beats everything else hands down
—————————————–
A Match/ Index combo is slightly slower than a Vlookup but more flexible.
But a Single Match column and multiple index columns is much faster than Vlookup. Index is super fast
—————————————–
Dynamic Names(with Index / Counta) are faster than Table References both of which are faster than full column references
Dynamic Names with UDF is faster than Index/Counta
However Fixed Range references are faster than Dynamic names of any kind
Here are my thoughts:
Sumproduct and DSum do slightly different things and the fact that DSun is faster kinda makes sense. However it’s easy enough to fall into the trap of relying on SP when other functions are better suited, I hardly every use Dsum, in fact I can’t think of a time I did, so this in a handy reminder! It also makes me think if there are other instances which I’m missing out on, I bet there are loads!
The Sumif functions seems to trump everything that has come before it (see the vlookup times too) we should try and use these as much as possible. Sumif’s are arguably easier to write and read the sumproducts too. If the data fits try and use sumifs in 2007 plus. The performance gains are vast!
Having said that there are some instances when only sumprodct will achieve what you need, and for small data sets or number of functions then the benefits might not be noticeable, but for large data sets and high numbers of function calls it’s worthwhile thinking hard about which function to use.
Indexing/match lookups are about twice as fast as the equivalent vlookups in this example, but be careful because often only one vlookup is needed, and the performance gains might not be as good. I really should test this, but I just want to make the post right now!
References to ranges act as you would expect. Tables in 2007 might be a bit slower than dynamic ranges – not sure there’s that much in it though, but there are significantly different – see t-test on wks. Again I would like to see how these results are effect by relative data set size and number of function calls.
So there you have it a fairly comprehensive look at various “lookup” functions in Excel and Excel 2007. Thanks to Sam for his hard work, putting the tests together and shearing his findings with us, good work Sam!
If you have a topic you’d like to be discussed on this blog, then feel free to leave a comment on the Request post and mail me any supporting data you have.
Download Workbook (.xlsm)
Tags: Functions
Categories: Downloads, Functions, General, Spreadsheet Design •
1 Comment »
26 October 2007 by Ross McLean
You know the score, you've done a pivot table and there are a load of empty cells. You want to fill them up:
[NB: you have to copy the PT as values or the code will fail!]
I use this almost every day:
VBA:
-
Sub fill_in()
-
Dim cell As Object
-
Application.ScreenUpdating = False
-
For Each cell In Selection
-
If cell.Value = "" Then
-
cell.Value = cell.Offset(-1, 0).Value
-
Else: End If
-
Next cell
-
Application.ScreenUpdating = True
-
End Sub
I think this may be a repost - I did look back but i could not find anything that i had done before, but i remember that Zack Barresse suggesting a none vba way that involvde a special paste of some sort.
Well there you are...
Tags: Examples, VBA
Categories: Functions •
5 Comments »
18 April 2007 by Ross McLean
I want to qualify this post. It's 11.20 and I've seen away a few.
Having said that this is a idea that was suggested to me by a member of www.eusprig.org
Lets do a little role play easy Simon ;-).
My name is Dave. I went to Manchester Uni. for 3 years, I've work as a VB dev for 5 years since I graduated. At the mo I work of a ISP that produces a manufacturing scheduling package. I follow all the best practices and am up to date with all the latest knowledge. The software I write is exceptional; my product can give a 20% performance increase to most customers.
Then there's Paul,
The model needs to be in by 10. It's this years spend forcaste; I only started to work on this last night at about 8. I need to get all the data from last year and apply this years growth, and the new Asia figures and the effects of the new IT systems. I don't have the IT figures, but I should get them, if not I'll wack in some figures.
So there you go.
Now let me tell you that this.
Dave's customers have a annual turn over of 5 million pounds.
Paul's net spend is 30 million.
Here's my question, where would you want the skilled computer programmer?
My point?
Excel more than any other application, is the one where programming skills are required writing SS formulas IS computer programming.
Your opinions are welcomed
Tags: Best Practice, VBA
Categories: Functions •
3 Comments »
22 February 2006 by Ross McLean
Here is some simple code to combine a selction of formulas into one cell. I have not tested it very much so it's not guaranteed. It will also add a few extra (), than might be needed.
VBA:
-
Sub CombineFormulas()
-
Dim objCell As Object
-
Dim sTemp As String
-
Dim sOperator As String
-
Dim rOutPut As range
-
-
On Error GoTo errorhandel
-
-
sOperator = InputBox("Operator to use?", "CombineFormulas")
-
-
For Each cell In Selection
-
If Len(cell.Cells.Formula)> 1 Then
-
''get the formula, adds a "(" , remove the "=", add the closing ")", and puts a "+" on the end
-
sTemp = sTemp & "(" & Right(cell.Cells.Formula, (Len(cell.Cells.Formula) - 1)) & ")" & sOperator
-
Else
-
End If
-
Next
-
-
''Puts an "=" at the start, then gets rid of the last "+",
-
sTemp = "=" & Left(sTemp, Len(sTemp) - 1)
-
-
Set rOutPut = Application.InputBox("Put In Cell", Type:=8)
-
-
ActiveSheet.range(rOutPut.Address).Formula = sTemp
-
-
Exit Sub
-
-
errorhandel:
-
MsgBox "Error: " & vbNewLine _
-
& Err.Description & vbNewLine _
-
& Err.Number, _
-
vbOKOnly, "CombineFormulas"
-
End Sub
Tags: Examples, VBA
Categories: Code, Functions •
No Comments »