assign a hotkey

I want to hit Ctrl +M and have this centre the content of a cell

Any ideas how to set this up  please ?
thfc9wigan1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Here's the macro.
Sub AlighnCenter()
    With ActiveCell
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
End Sub

Open in new window


To add the macro

In Excel, Press Alt+F11 to open Visual Basic Editor (VBE)

Right-click on your workbook name in the "Project-VBAProject" pane (at the top left corner of the editor window) and select Insert -> Module from the context menu

Copy the macro and paste it into the right-hand pane of the VBA editor ("Module1" window)

Press Alt+F11 again to go back to Excel

Press Alt+F8 to open the "Macro" dialog window. Select the macro, click ‘Options…’,  enter the letter 'm' in the small box and click ‘OK’.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thfc9wigan1Author Commented:
excellent, BUT ...
 
... how do I make this apply to ALL excel files - both existing and future ?
0
thfc9wigan1Author Commented:
Please ignore the last comment - it does work in current and a freshly created file

Thank You
0
thfc9wigan1Author Commented:
works well

Thanks for clear instructions, even for someone not familiar to VBA.  Only hairy moment is trying to copy macro when bigger than embedded window
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help. I'll make sure I mention the EE 'Select All' button next time.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.