Solved

Toolbar button to apply custom number format

Posted on 2014-03-28
13
1,253 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 14

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 14

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 14

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
 
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 14

Expert Comment

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

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

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

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 14

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 14

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will show you how to use shortcut menus in the Access run-time environment.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now