Friday, December 4, 2009

[Charts] How to Display Totals on a Stacked Column (Bar) Chart

Lets say, there is a stacked column chart in Excel created using the data as shown:
Data table for Stacked Column Chart in Excel

How to create Stacked Column Chart in Excel
Now, we want to display totals, for example 34 + 43 = 77 at the top of the stacked columns. In stacked column chart, Excel does not allow the "Outer End" option of Data Label position.

To overcome this limitation, create a "Total" column in the data table as shown:

How to add total at top of Stacked Column Chart in Excel
Now change the source data of the chart to include column D as shown below:
The Total column will appear as show above.
Next, right-click on the new "total" series and change the Chart Type to Line and the resulting chart is shown below:
Data table for Stacked Column Chart in Excel
Next, double-click on the Line and set the Line color as "None" and Marker as "None" under the "Patterns" tab.
Go to "Data Labels" tab and select "Value" checkbox, and the resulting final chart will look like this:
Data table for Stacked Column Chart in Excel
Hope you found this tutorial helpful.

Tuesday, December 1, 2009

[Excel] Creating a Custom Menu/Command bar Using VBA Macro and Add-Ins

This macro creates a custom command bar at the bottom part of the Excel window as shown.


Custom Menu/CommandBar Addin
The command bar has three menu items. Each of the menu items are assigned to a macro.
Here is how to go about creating a custom command bar:

Step 1: Create a new Excel file and use the code below to create your own command bar
Step 2: Save the file as an AddIn, for example "Utility.xla".
Step 3: Go to Tools -> Add-ins and browse the addin file you created as shown. Each time Excel is opened, this add-in is called and the Command Bar is ready to use.

Custom Menu/CommandBar Addin



'=========================================================================
' Creating Utility Command Bar with Button Menu Items with Icons
' Copyright vbacentral.blogspot.com
'=========================================================================
Option Explicit

Sub Create_Utility_Menu() Dim MyBar As CommandBar Dim MyPopup As CommandBarPopup Dim MyButton As CommandBarButton ' Delete Menu, if it was already created On Error Resume Next CommandBars("Utility Menu").Delete On Error GoTo 0 ' Create a Command Bar object on the bottom of the Excel window Set MyBar = CommandBars.Add(Name:"Utility Menu", _ Position:=msoBarBottom, Temporary:=True) With MyBar '.Width = 200 .Visible = True Set MyButton = MyBar.Controls.Add(Type:=msoControlButton) With MyButton .Caption = "Move Sheets Around" .Style = msoButtonIconAndCaption 'Other Menu item types include: 'msoButtonAutomatic, msoButtonIcon, msoButtonCaption, or msoButtonIconandCaption .BeginGroup = True 'Assign a macro (in this case macro name is MoveSheets) .OnAction = "MoveSheets" 'Assign a picture icon using predefined Office icons .FaceId = 1771 End With Set MyButton = MyBar.Controls.Add(Type:=msoControlButton) With MyButton .Caption = "Hide/Unhide Sheets" .Style = msoButtonIconAndCaption .BeginGroup = True 'Assign a macro (in this case macro name is HideUnhideSelectedSheets) .OnAction = "HideUnhideSelectedSheets" 'Assign a picture icon using predefined Office icons .FaceId = 488 End With Set MyButton = MyBar.Controls.Add(Type:=msoControlButton) With MyButton .Caption = "Go to Sheet" .Style = msoButtonIconAndCaption .BeginGroup = True 'Assign a macro (in this case macro name is GoToSheet) .OnAction = "GoToSheet" 'Assign a picture icon using predefined Office icons .FaceId = 917 End With End With End Sub