Solved

Toolbar button to apply custom number format

Posted on 2014-03-28
13
1,924 Views
Last Modified: 2014-03-28
I have a custom number format in Excel, which I can apply to a cell by right clicking, choosing Format Cells, then on the Number tab selecting Custom and entering/selecting the format #,##0.00 ;(#,##0.00)
 
How can I add a toolbar button in Excel 2013 to format cells that way without having to go through those three steps?  

Quick access toolbar or Ribbon, no preference - whichever is easier
0
Comment
Question by:RedLondon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
13 Comments
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961190
The VBA would be:

Sub applyFormat()

ActiveCell.NumberFormat = "#,##0.00 ;(#,##0.00)"


End Sub

Open in new window


You can add to QAT easiest
0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961196
Steps:
1. Alt + F11 to open the VBA Env
2. Paste the macro into ThisWorkbook
3. Save
4. On ribbon - right click, select Customise Quick Access Toolbar
5. In "Choose Commands From" select Macros
6. Select the macro "applyFormat"
7. Add to QAT
8. Assign a button & rename & OK
9. select a cell with numbers and press your new button
0
 
LVL 15

Accepted Solution

by:
DrTribos earned 500 total points
ID: 39961208
Or... (learning on the fly)  to apply the formatting to a selection of cells...

Sub applyFormat()
Dim selRng As Range
 Set selRng = Selection
    selRng.NumberFormat = "#,##0.00 ;(#,##0.00)"
End Sub

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:RedLondon
ID: 39961236
That's great - works perfectly, but the file I saved the macro in opens every time I press the button, is there a way to stop that (or to close it automatically)?

I had to save the workbook in a "Excel workbook with macro support" filetype and click to 'Enable' the macro the first time I opened it, but the PC remembers that I trust that file afterwards - that's fine, but the file keeps opening so it'd be great if we could stop that
0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961245
Oh... lemme check...  BRB
0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961252
I'm not sure of the BEST way to do this but... try:
Put the macro in to an otherwise empty spreadsheet, do the QAT thing, then Save As - using "Excel Add-In"

the Save As dialog will then take you here:
"C:\Users\Red London\AppData\Roaming\Microsoft\AddIns"

I have not actually tested this in Excel (I have done similar in PPT) but it should then become global...
0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961261
Yikes - scratch that. It does not work.
Lemme test some more things
0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961267
The steps are outlined here - very different to MS Word which is where I usually play :-)
0
 
LVL 11

Author Comment

by:RedLondon
ID: 39961271
Perfect - saving as an Addin did work, I just had to enable the addin at File -> Options -> Addins -> Manage Excel Addins
0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961280
Oh... cool I didn't get it to work.  I ticked the box but it seemed to open the original file as you mentioned.... perhaps I'm just tired.  

Glad you got it working
0
 
LVL 11

Author Comment

by:RedLondon
ID: 39961285
I deleted the QAT button I created first, deleted the Macro enabled Workbook, then did the addin - I think your button is still working from the first route rather than the second

Thanks again
0
 
LVL 15

Expert Comment

by:DrTribos
ID: 39961296
Doh - I forgot to undo my first QAT... yep must be tired... I also got it working in the personal book as per the article.  Not sure of the pros and cons of either approach.
0
 
LVL 11

Author Comment

by:RedLondon
ID: 39961311
Just added it as an Add-in on the customer's PC and he's happy with it, so I'm happy.

I'll be re-reading this in a couple of years when he gets a new PC and complains that that button is missing, wondering how the hell I got it there for him in the first place!

(I'd already created him a custom group on his Home ribbon tab, so his button is happily on that now)

Many thanks, go to bed if you're tired :)
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question