Excel VBA Programming Book (with real life examples) - Ravi SagarRecent blog postsNavigation |
Merge/DeMergeThis is another example to create a Macro to Merge and De-Merge the selected cells quickly, which is otherwise a long procedure. Steps to create a Macro for Merge 1. Start Macro Recorder and name it as "MergeCells" Press ALT + F11 and open the Visual Basic Editor. You will see that the following code is generated. Sub MergeCells() ' ' MergeCells Macro ' Macro recorded 3/7/2008 by Ravi Sagar ' ' With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = False End With Selection.Merge End Sub Do not worry much about all the lines written here. The only thing that should be your concern is the line Selection.Merge, it tells Excel to Merge the selected cells. Steps to create a Macro for DeMerge 1. Start Macro Recorder and name it as "DeMergeCells" Press ALT + F11 and open the Visual Basic Editor. You will see that the following code is generated. Sub DeMergeCells() ' ' DeMergeCells Macro ' Macro recorded 3/7/2008 by Ravi Sagar ' ' With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .ShrinkToFit = False .MergeCells = False End With End Sub In this code the statement .MergeCells = False unmerges the selected cell. |
Recent comments
21 weeks 3 days ago