I was recently working on an Excel spreadsheet with a VBA module that inserted formulas with the MROUND function.
range.formulaR1C1 = "=MROUND(RC[-1],.02)"
The MROUND function is quite handy, it takes the value of the calculation and rounds it to the nearest value specified in the second argument (as opposed to the ROUND() fucntion which jsut rounds to the nearest significant digit) It is found within the "Analysis Toolpak" Add-in.
A colleague ran the spreadsheet and the darned thing fell over. It turns out they also had the add-in "Analysis Tookpak - VBA" installed. When we turned it off, it ran fine so now the code turns it off automatically.
Sub Workbook_Open()
If AddIns("Analysis Toolpak - VBA").Installed = True Then
continue = msgBox("Turning off Analysis Tookpak - VBA",vbOkCancel)
If continue = 2 Then
Exit Sub
Else
AddIns("Analysis Toolpak - VBA").Installed = False
End If
End Sub
Oh the joys of manipulating data. I work in the NHS and for retail organisations, helping to make sense of the raw data that they generate. The tools available are varied and almost always wrong the wrong ones :) This blog is my incidental musings of things that have frustrated or interested me and I hope they will help to overcome some of the pitfalls I have encountered or inspire you to find new ways to solve your problems.
Wednesday, 12 October 2011
Thursday, 6 October 2011
Excel VBA: Application.GetSaveAsFilename
I discovered today that there is some undocumented protections built into the GetSaveAsFilename method. If you supply a filename with fullstops in it but without a valid extension then the filename that appears in the dialog box will be surrounded by quotes so make sure that you always append the correct filetype to the end of the filename if you are pulling the filename from a variable.
Subscribe to:
Posts (Atom)