Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Excel VBA tip: Why do I get the error "Object variable or With block variable not set"?

A commonly encountered error when developing Excel VBA is the fairly cryptic "Run-time error '91': Object variable or With block variable not set".

Today I'm going to attempt to explain what it means and some common causes.  Click read more...

Excel tip: you can write your own worksheet functions in VBA to make things easier!

If you've ever wanted a worksheet function to do something that isn't supported by the built-in worksheet functions, consider writing your own function using VBA.

It's very easy to do, but there are two drawbacks to be aware of: (1) the workbook must be macro-enabled; (2) your function could perform slower than an equivalent built-in function.

To find out how to write your own, click read more...

Excel VBA tip: worksheet functions can be called from within VBA using Application.WorksheetFunction

Trying to do something within VBA that can be easily achieved using a formula in a cell on a worksheet?  You can probably use a VBA worksheet function.

Call a worksheet function by using Application.WorksheetFunction.  For example:

Excel VBA tip: use "VBA." to show a list of available functions

If you want to know which VBA functions are available, type "VBA." (no quotes).  Provided you have Auto List Members switched on in the VBA options you will be shown a list of all of the available functions:

Excel VBA tip: press F2 to display the Object Browser

When in the Visual Basic Editor, pressing F2 displays the Object Browser.  This is a really handy tool that allows you to browse through each class and view its members.  Click on a class to see the members, then click on a member to see further details.

Excel tip: did you close a workbook without saving and need to get it back? Here's how to recover it!

Open the document you forgot to save.  Go to File > Info and look in the Versions section towards the bottom and you should see your unsaved versions.  You can then open the required version and click the Restore button that appears below the ribbon.  Note: this behaviour is only supported in Excel 2010 onwards.

From Excel 2010 onwards the Autorecover feature in Excel is very good.  It will save versions of files that you closed without saving, including documents you created and never saved.

If you are trying to recover a file that was never saved, click the Manage Versions button, then Recover Unsaved Workbooks.  You should see the workbook in there.  Workbooks are kept for 4 days.



By default Excel saves your documents in the background every 10 minutes.  You can change this by heading over to File > Options > Save and adjusting the time interval.  Having it set to 10 minutes means you'll lose at maximum the last 10 minutes of work should something go wrong.

Excel tip: use Evaluate Formula to track down errors such as #NAME?, #REF! and #VALUE!

If you're having trouble working out why a formula displays an error such as #NAME?, #REF!, #VALUE!, #N/A or #DIV/0! you can use Evaluate Formula to help identify step-by-step what happened.

Select Evaluate Formula from the Formula Auditing group on the Formulas tab.  Click read more for detailed more help on how to use Evaluate Formula.

Excel tip: show formulas in cells instead of values to help troubleshooting

Having trouble with a formula or trying to learn the formulas used on somebody else's worksheet?  Use "Show Formulas" to show formulas instead of values.

"Show Formulas" is a toggle that can be found on the Formulas tab in the Formula Auditing group.  When in Show Formulas mode, clicking on a cell highlights the cells used in the formula for easy viewing.  Turning off the toggle returns to normal viewing mode.

Excel tip: use F2 when editing a "Refers to" or "Applies to" field

Fed up of using the cursor keys whilst editing a "Refers to" or "Applies to" field and finding a cell reference appears in the middle of your formula?  Pressing F2 toggles between 'point mode' and normal 'editing mode'.