|
|
| Back to Excel Homepage | Excel VBA - Reference Guide |
|
Menu With...End With blocks
Other links
|
The With…End With block instruction enables you to perform multiple operations on a single object. This is another way to make the code execute more quickly and code styles more efficient.
The following procedure will format the selected cells with the font ‘Times New Roman’, font size 12, Bold, Italic and the colour Blue.
The above procedure can be rewritten using a With…End With block as follows:
Using the this type of block, your code is cleaner and easier to maintain. The With...End With block encapsulates the object and member without the need to repeat unnecessary (duplicate) code.
If fact, when you record a macro and you navigate through the dialog boxes making various changes before choosing the OK button you in fact capture the code using the above structure. Try the Font Dialog box whilst recording the macro.
|
VBA Keywords: Selection, Name, Font, Bold, Italic, ColorIndex and Size.. |
|
© copyright 2010 TP Development & Consultancy Ltd, All Rights Reserved. All trademarks are copyrighted by their respective owners. Please read our terms of use and privacy policy. |