Sunday, July 27, 2014

Excel Macro VBA - Clear Method

Clear Method is used to remove the contents and cell formatting of a range. This method should not be used if you EITHER just want to remove the contents of a range and do not want to remove the cell formatting OR just want to remove the cell formatting and do not want to remove the contents of a range. The following example will help to understand better.


Example:


Let us clear the contents and format of cells B5, C5 and D5 using Clear method. Run a macro with the following procedure:

Sub Clr()

    Range("B5:D5").Clear

End Sub

Output:





























Notice all the differences happened to the cells in the cleared range
  • The contents of the cells are cleared
  • The border of the cells is cleared and set to template default
  • The background color of the cells is set to template default i.e. White
  • The font color of the cells is set to template default i.e. Black
  • The font type and size of cells are changed from Arial 9 to template default i.e. Calibri 11
  • The vertical alignment of the cells are changed from Middle Align to template default of Bottom Align.
  • The horizontal alignment of the cells are set to template default i.e. Align Left

Please visit following posts to know about other clear methods available with Excel VBA

ClearContentshttp://foryourread.blogspot.in/2014/07/excel-macro-vba-clearcontents.html

ClearFormatshttp://foryourread.blogspot.in/2014/07/excel-macro-vba-clearformats.html

ClearCommentshttp://foryourread.blogspot.in/2014/07/excel-macro-vba-clearcomments.html 

ClearHyperlinkshttp://foryourread.blogspot.in/2014/07/excel-macro-vba-clearhyperlinks.html

ClearNoteshttp://foryourread.blogspot.in/2014/07/excel-macro-vba-clearnotes.html

ClearOutline - http://foryourread.blogspot.in/2014/07/excel-macro-vba-clearoutline.html

Friday, July 25, 2014

Excel Macro VBA - ClearOutline Method

ClearOutline method is used to clear outline of a range. It actually excludes the range from the outline group. Let us take a look at the following example:

There is an outline from A2 to C4 in Sheet 1.

Sheet 1 – Collapsed


Excel Macro VBA - Copy Paste Without Selecting A Range

How do we copy and paste a range without selecting it?

How do we significantly reduce the lines of code to perform a copy and paste?

Consider the following example:

Sheet 1: