Solved

Toolbar button to apply custom number format

Posted on 2014-03-28
13
1,556 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
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Outlook Free & Paid Tools
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

829 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