PTS Blog

Custom Solutions | Commercial Utilities | Training | Charts and Tutorials | PTS Blog

 

Main menu:

 
Peltier Tech
Chart Utilities

PTS Waterfall Chart Utility
PTS Cluster-Stack Column Chart Utility
PTS Box and Whisker Chart Utility
PTS Marimekko Chart Utility
PTS Dot Plot Utility
PTS Cascade Chart Utility

Subscribe

Site search

Subscribe

Site search


Recent Posts

Recently Commented

Popular Posts

Archive


 

Categories


 

Buy me a coffee

If this topic or the whole blog has been helpful, support further development by treating me to a cup of coffee.


Privacy Policy

Creative Commons License
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

How To: Record Your Own Macro

by Jon Peltier
Peltier Technical Services, Inc., Copyright © 2009.
Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.

In a recent post, I showed how to copy someone else’s VBA procedure (i.e., “macro”) and paste it into your own workbook. Fortunately you don’t have to rely on others for custom macros. Excel includes a Macro Recorder which captures your actions, so that you can replay them later, saving yourself time and keystrokes.

It’s easy to record and rerun macros. You can start the Macro Recorder in a number of ways.

  • Tools menu > Macro > Record New Macro
  • Record Macro button on the Visual Basic toolbar
  • Record Macro Button

    The Macro Recorder will now record all of your steps until you turn it off, using one of several methods.

    • Tools menu > Macro > Stop Recording
    • Stop Recording button on the Visual Basic toolbar
    • Stop Recording button on the Stop Recording toolbar

    Stop Recording Button  Stop recording Button

    To see your handiwork, go to the VB Editor (VBE). There are three ways to get there:

    • Tools menu > Macro > Visual Basic Editor
    • Visual Basic Editor button on the Visual Basic toolbar
    • Shortcut key combo Alt+F11

    VB Toolbar - VB Editor Button

    If your workbook had no macros to begin with, the Macro Recorder creates a new code module, which you can see in th Project Explorer Window. If the Project Explorer isn’t visible, go to View menu > Project Explorer.

    Project Explorer

    To view the macro you’ve recorded, double click on the new code module.

    Code Module with Recorded Macro

    The macro can be run in a number of ways:

    • Tools menu > Macro > Macros, select the Macro, and click Run
    • Shortcut Key combo Alt+F8, select the Macro, and click Run
    • Run Macro button on the Visual Basic toolbar, select the Macro, and click Run
    • Click in the macro with the mouse and press F5

    Run Macro Button

    This is the first exposure most people have to VBA programming. In a series of upcoming posts, I’ll cover the following VB topics:

    Possibly Related Posts:

    Bookmark and share this entry:
    • Digg
    • del.icio.us
    • Facebook
    • Technorati
    • Twitter
    • StumbleUpon
    • Google Bookmarks
    • Reddit
    • MySpace
    • Slashdot
    • LinkedIn
    • Yahoo! Buzz

    Learn how to create Excel dashboards.

    Comments


    Comment from Postal Bob
    Time: Friday, October 17, 2008, 12:10 pm

    I need instructions on how to program 1 cell on a worksheet so that when you click on it it deletes the data that has been entered in unprotected cells. Can this be done? I have to present this to my boss the end of next week and he’s a computerphob, the easier it is the better he likes it. Thanks


    Comment from Jon Peltier
    Time: Friday, October 17, 2008, 12:57 pm

    Bob -

    Here’s a procedure that will clear unprotected cells in the active sheet. Place it in a regular module in the workbook.

    Sub ClearUnlockedCells()
      Dim r As Range
      Dim iCalc As Long
    
      Application.ScreenUpdating = False
      iCalc = Application.Calculation
      Application.Calculation = xlCalculationManual
      For Each r In ActiveSheet.UsedRange.Cells
        If Not r.Locked Then
          r.ClearContents
        End If
      Next
      Application.ScreenUpdating = True
      Application.Calculation = iCalc
    End Sub

     
    Don’t use a cell as the trigger, open the Forms toolbar, and stick a button on the sheet. When the Assign Macro dialog pops up, select the above macro. Then change the caption on the button to something like “Clear Inputs”. Then protect the sheet.

    Write a comment

    I welcome comments from my readers. If you have an opinion on this post, if you have a question or if there is anything to add, I want to hear from you. Whether you agree or disagree, please join the discussion.

    If you want to include an image in your comment, post it on your own site or on one of the many free image sharing sites, and include a link in your comment. I'll download your image and insert the necessary html to display the image inline.

    Read the PTS Blog Comment Policy.





    Subscribe without commenting

    PTS Waterfall Chart Utility PTS Cluster-Stack Column Chart Utility PTS Box and Whisker Chart Utility PTS Marimekko Chart Utility PTS Dot Plot Utility PTS Cascade Chart Utility

    Create Excel dashboards quickly with Plug-N-Play reports.