I hate merged cells. They create all sorts of problems adding/deleting columns,
filling down, etc. But it can look nice to have text centered across a range
not just a single cell. Luckily, Excel provides the rarely used Align Center
formatting option. This macro provides easy access to toggling the alignment
formatting across all selected cells… but that’s not all… :-) it also
centers the contents of a single cell if that is all that is selected.
' Toggles Align Center
' Copyright under GPL by Mark Grimes
' Keyboard Shortcur: Crtl+Shift+A
'
Sub mgCenterAlign()
If Selection.count = 1 Then
With Selection
If .HorizontalAlignment = xlHAlignCenter Then
.HorizontalAlignment = xlGeneral
Else
.HorizontalAlignment = xlHAlignCenter
End If
End With
Else
With Selection
If .HorizontalAlignment = xlCenterAcrossSelection Then
.HorizontalAlignment = xlGeneral
Else
.HorizontalAlignment = xlCenterAcrossSelection
End If
End With
End If
End Sub
The contents of this blog are licensed under the Creative Commons “Attribution-Noncommercial-Share Alike 3.0″ license.