Excel Tips & Tricks 4 : 


Running totals

Question:
How do I have excel do a running total.
In other words; I want to be able to type a figure in and excel take the last figure - add the two figures together - then put the new total under the last/old total?


The following is the macro that will do a running total for you.
Here is how it works.
You select the cell with the last figure in it.
Then run the Macro - You get an input box - type in the new figure - click OK

Sub runtotals()

          currentfigure = ActiveCell.Value
          Value = InputBox("Type in your amount to add to running total")
          Value2 = Value + currentfigure
          ActiveCell.Offset(1, 0).Range("A1").Select

          ActiveCell.FormulaR1C1 = Value2


End Sub

You get the new total in the cell under the figure you selected.

If you want to automate this a little. Place a button on the worksheet, so all you need to do is: Select the cell with the last figure then click the button.
If you want to get real automated, you can have it loop until you stop putting something in the input box.

To the Top


Charts With Art

Want to spruce up Excel charts? Your options are many. Right-click any element and select the Format option. Under the Patterns tab, experiment with Fill Effects textures and click OK twice to make a selection. Use this technique to add an eye-catching background to a bar chart: Click on the plot area behind the bars, select Format Plot Area, and under the Picture tab, select an appropriate graphic.

To the Top

 


Custom Views

  1. Turn on your autofilter for your list.
  2. Then click Tools, Customize
  3. Under Categories select View
  4. Then select Custom Views...
  5. Drag it up to the toolbar. Then close the Customized dialog.
  6. click a down arrow for filtering (to filter a column)
  7. Then in the Custom Views text box type a name to call this view and press enter

Now you have a name for a filtered item. Just keep adding name to your filtered items.

To the Top


Sort worksheets

Just copy this Macro and paste it on a module sheet in Excel 97, 2000, 2002, 2003. Then run the macro "Sort_Active_Book".

Sub Sort_Active_Book()
Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult
'
' Prompt the user as which direction they wish to
' sort the worksheets.
'
iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
& "Clicking No will sort in Descending Order", _
vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
For i = 1 To Sheets.Count
For j = 1 To Sheets.Count - 1
'
' If the answer is Yes, then sort in ascending order.
'
If iAnswer = vbYes Then
If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
'
' If the answer is No, then sort in descending order.
'
ElseIf iAnswer = vbNo Then
If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then
Sheets(j).Move After:=Sheets(j + 1)
End If
End If
Next j
Next i
End Sub

To the Top


Proper Case

Take all of the code below, from Sub to End Sub and copy it.

  1. Open Excel, Click on Tools, Macro, Visual Basic Editor.
  2. In the Editor, Press the F7 key (this will open a code window)
  3. Paste the code in this window.
  4. Save and return to Excel worksheet.
  5. Select the column that has all upper case or all lower case.
  6. Run the macro (Tools, Macro, Macros...)
  7. Double-Click on the Proper_Case macro.

Sub Proper_Case()

'above name of macro

'the next line selects the column

Range(Selection, Selection.End(xlDown)).Select

'The next line setup the active cell in the selected area as an individual item. Set C = ActiveCell

' X in the for each loop is really the C or the active cell

' so the macro will follow the selected range to the end

' Loop to cycle through each cell in the specified range.

For Each x In Selection

' There is not a Proper function in Visual Basic for Applications.

' So, you must use the worksheet function in the following form:

x.Value = Application.Proper(x.Value)

Next

End Sub

 

To the Top

Make everything in the column lower case

Sub Lower_Case()
'above name of the macro

'the next line selects the column(s)
Range(Selection, Selection.End(xlDown)).Select 'The next line setup the active cell in the selected area as an individual item.
Set C = ActiveCell

' X in the for each loop is really the C or the active cell
' so the macro will follow the selected range to the end
' Loop to cycle through each cell in the specified range.
For Each x In Selection
'LCase is the function to make all letters lower case.
x.Value = LCase(x.Value)


Next
End Sub
 


Links for your convenience

Webmaster: E-Mail Address
Copyright © 1997 [BCA]. All rights reserved. -
Revised: March 15, 2008.