Latest posts by techwriter (see all)
- English Grammar – How to Use LIE and LAY Correctly - October 26, 2016
- How to Count the Number of Days with an Incident and Chart with Running Averages in MS Excel - October 19, 2016
- FREE Online Video Course – MS Word Power Shortcuts - October 14, 2016
© Ugur Akinci
Merging MS Excel cells and centering the contents is so easy: you just select the cells and click the Merge & Center button on the Home tab of the ribbon.
But what if you don;t want the content to center? What if you’d like to left- or right-justify the text within the merged cells?
Then you need a simple macro.
1) Press Alt + F11 to display the VBA Editor.
2) Select the Worksheet you’re working on from the VBA Project pane.
3) Right click and select New > Module to create a new module.
4) Click the new module to enable its code pane on the right:
5) In the code pane, enter this VBA code:
Sub MergeRight() With Selection .HorizontalAlignment = xlRight .Merge End With End Sub
6) Save your workbook and switch back to your worksheet (Alt + F11).
7) Select the cell range you like.
8) On the ribbon, select Developer. Click Macros to display the list of macros recorded. Your MergeRight macro should be there:
9) Select the macro and click Run to right-merge all your content:
Similarly, to merge and left-justify your content, you can change the “xlRight” in the VBA formula to “xlLeft“.
But even simpler, just select the Merge Across option from the Merge & Center drop-down list: