Easy Center Across Selection

In Favourite Free Excel Add-Ins, one of the commenters (and Debra) complains about the Center Across Selection being buried in the Format Cells dialog.

It is possible to make this a one step process, using VBA.

Unfortunately this approach does require macros in your workbook, but if you are already storing your oft-used macros in PERSONAL.XLS, then this should not be a problem.

Sub CAS()
If TypeName(Selection) <> "Range" Then Exit Sub
Selection.HorizontalAlignment = xlCenterAcrossSelection
End Sub

Just assign this to a toolbar button and put it next to the Merge And Center button, just to taunt it. Or remove the Merge And Center button altogether and put this one in its place.

Stay tuned, the next post will have more about toolbar buttons.

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 4 Comments:

  1. Jon Peltier writes:

    "Or remove the Merge And Center button altogether and put this one in its place."

    Yep. I wrote a similar macro, assigned it to a button, and replaced the M&C button with it. I did this back in Excel 97. I think Excel 95 was the first version that allowed merged cells, but prior to that there was only center across selection.

    • JP writes:

      I like how you can just hold the Alt button and click-drag buttons off the toolbar. When I see some horrid worksheet and find merged cells, it's the first thing I think of.

  2. Debra Dalgleish writes:

    I've got a variation of your code, that I use to fix up workbooks other people have formatted:

    With Selection
    .UnMerge
    .HorizontalAlignment = xlCenterAcrossSelection
    End With

Comments on this article are closed. Why?

Site last updated: February 9, 2012