Tips.Net > ExcelTips Home > Macros
The following are additional topics related to the category listed above. A bracketed number after the topic indicates how many articles are related to that subject.
The following articles are available. Click the article's title (shown in bold) to see the associated article.
Adding a Macro to a Toolbar Macros can make Excel much more powerful, allowing you to quickly perform repetitive tasks, process data, and do just about anything else you can think of. To make your common macros easier to use, it helps to add them to a toolbar where they are only a click away. Microsoft Excel versions: 97 2000 2002 2003
Assigning Macros to Graphics Depending on your version of Excel, macros are usually added to toolbars and menus. You can also add them to graphics, so that the macro is executed when someone clicks on the graphic. This tip explains how to establish that relationship between a graphic and a macro. Microsoft Excel versions: 97 2000 2002 2003 2007
Changing Directories in a Macro Macros can do all sorts of manipulations of files and directories. One command you can use is the ChDir command, which allows you to change from one disk directory to another. Microsoft Excel versions: 97 2000 2002 2003 2007
Changing the Default Drive Macros often need to work on various files on your disk drive in order to process data in a worksheet. You can specify the drive that your macro should use as “default” by using the command described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Clearing the Undo Stack in a Macro The Undo stack is cleared automatically whenever you run a macro. This fact of Excel’s behavior allows you to easily clear the stack from within the macro itself. Microsoft Excel versions: 97 2000 2002 2003 2007
Comparing Strings Comparing strings is something that is routinely done in a macro, particularly when getting input from a user. To successfully compare what is entered with a value, you need to do some conversions on the data entered. This tip explains the logic behind such an approach, along with an example of how to do it. Microsoft Excel versions: 97 2000 2002 2003
Controlling the Behavior of the Mouse Wheel If you have a mouse that has a track wheel between the two buttons, you can use that wheel to help navigate around your worksheets. In order to do that, you need to make a small configuration change to Excel, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Controlling the Printer in a Macro Want to access the advanced features of your printer from within a macro? You may be out of luck, as those features are often not made accessible to VBA macros. This tip examines why this is the case. Microsoft Excel versions: 97 2000 2002 2003 2007
Converting Numbers to Strings Need to convert a numeric value into a string? It’s a snap to do by using the Str function in your macros. Microsoft Excel versions: 97 2000 2002 2003
Converting Strings to Numbers When creating a macro, you’ll often need to convert strings to numbers. For instance, you might have some user input that needs to be converted. This is done using the Val function, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003
Counting Commas in a Selection If you have a range of cells in which you want to count all the commas, there are several ways you can derive the figure you need. This tip examines different methods to achieve the count, and you can easily adapt the methods to count other characters. Microsoft Excel versions: 97 2000 2002 2003 2007
Counting Precedents and Dependents Do you need to know how many precedents or dependents there are on a worksheet? You could count them manually, or you could let a short macro derive the information for you. Microsoft Excel versions: 97 2000 2002 2003 2007
Creating a Directory in a Macro When you create macro, you might want to use it to create a folder on your hard drive. You can accomplish this with one simple command, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Creating a Plus/Minus Button The plus/minus button on a calculator provides a quick way to change a value from a positive to a negative value, and back again. There is no such button in Excel, but you can create one easily by applying the macro in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Creating a String in a Macro In VBA, the String function can be used to create a string consisting of almost any number of characters. This tip explains how to use the function in your own macros. Microsoft Excel versions: 97 2000 2002 2003
Creating Add-Ins Add-ins are special Excel programs that enable features or capabilities not in the original program. This tip explains how you can create your own custom add-ins from a regular workbook. Microsoft Excel versions: 97 2000 2002 2003
Creating Worksheets with a Macro Using a macro to add worksheets to your workbook is easy. This tip provides two different methods you can use. Microsoft Excel versions: 97 2000 2002 2003 2007
Debugging a Macro Develop your own macros and, sooner or later, you will need to debug them. The VB Editor provides a couple of fundamental debugging tools, introduced in this tip. Microsoft Excel versions: 97 2000 2002 2003
Default Worksheet when Opening When opening a workbook, you may want to make sure that a particular worksheet is always displayed first. The only way to ensure this is through the use of a macro, described here. Microsoft Excel versions: 97 2000 2002 2003 2007
Deleting a File in a Macro Need to delete a file within your macro? If you know the path and name of the file, it is easy to do with a simple command. Microsoft Excel versions: 97 2000 2002 2003 2007
Deleting a Macro Don’t need that old macro any more? Here’s how to get rid of it so that it is no longer a part of your workbook. Microsoft Excel versions: 97 2000 2002 2003
Delimited Text-to-Columns in a Macro Macros, in processing data, may need to spread text out among different columns in a worksheet. This tip explains how you can utilize the power in Excel’s Text-to-Columns tool from within your own macros. Microsoft Excel versions: 97 2000 2002 2003
Deriving an Absolute Value in a Macro Need to figure out an absolute value within your macro code? It’s easy to do using the Abs function, described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Deriving the Worksheet Name Using a macro to reference the worksheet tab name in a worksheet cell in Excel. Microsoft Excel versions: 97 2000 2002 2003
Determining a Worksheet's Number When you add a new worksheet to a workbook, it receives a meaningful name such as “Sheet4” or “Sheet17.” If you want to determine a worksheet’s number—even after you change the worksheet’s name—here’s how to do it. Microsoft Excel versions: 97 2000 2002 2003 2007
Determining an ANSI Value in a Macro If you need to know the character code of a particular character, you can use the Asc function. This tip shows you how. Microsoft Excel versions: 97 2000 2002 2003 2007
Determining an Integer Value You can use the Int function, in a VBA macro, to return the integer portion of a value. This can be very handy in many types of data processing. Microsoft Excel versions: 97 2000 2002 2003
Determining How Many Windows are Open Does your macro need to know how many windows Excel has open? You can determine it by using the Count property of the Windows group. Microsoft Excel versions: 97 2000 2002 2003 2007
Determining if Calculation is Necessary When writing macros, you can turn off the automatic recalculation feature of Excel so that your macro isn’t slowed down. When the macro is done, you may want to figure out if doing a recalc is necessary. This tip explains how you can figure this out. Microsoft Excel versions: 97 2000 2002 2003
Determining Mouse Cursor Coordinates On a Graphic Add a graphic to a worksheet as part of an Image object, and you can use some very handy event handlers to figure out the coordinates of the mouse pointer. Here’s how to make it work. Microsoft Excel versions: 97 2000 2002 2003 2007
Determining the Hour of the Day Need to know what hour of the day a macro is running? You can determine the information by using the Hour function, described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Determining the Length of a Text File When creating a macro to process a text file, you may need to know the length of that file. You can figure this out by using the LOF function, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Develop Macros In Their Own Workbook If you develop macros and edit them quite a bit, you may be running the risk of causing problems with the macros or with your workbooks. This tip explains a general way that you can avoid the potential problem. Microsoft Excel versions: 97 2000 2002 2003 2007
Developing Reciprocal Conversion Formulas Would you like to develop a worksheet that has two cells that will convert whatever is entered in either of the cells? For instance, you might put a measurement in inches in one cell and have it converted into millimeters in the other, and vice versa. This tip explains how you can (and why you must) do this using macros. Microsoft Excel versions: 97 2000 2002 2003 2007
Digital Signatures for Macros The security features built into Excel 2002 and 2003 allow you to digitally sign your macros so that users can rest assured that they remain unchanged since you saved them. Understanding digital signatures and the certificates on which they are based can be a bit perplexing, but the information in this tip can go a long way toward clearing the air. Microsoft Excel versions: 2002 2003
Disabled Macros Do your macros seem to be disabled on your new machine? It could be because of the security settings in Excel. Here’s where they are located and how to change them. Microsoft Excel versions: 2000 2002 2003 2007
Displaying a Set Column Range You may want to display a specific range of columns in Excel’s program window. You can do this with a simple macro that makes use of the Zoom feature built into Excel. Microsoft Excel versions: 97 2000 2002 2003
Displaying Messages When Automatic Data Changes Worksheets can be set up so that they are automatically updated with data pulled from a variety of sources. As data changes in this manner, you may want to be notified when certain criteria are met. This tip describes how you can achieve the type of notification you need in such a scenario. Microsoft Excel versions: 97 2000 2002 2003
Dissecting a String The VBA programming language used in Excel has a number of functions that allow you to “pull apart” text strings. This tip examines the most common functions and how you can use them in your processing. Microsoft Excel versions: 97 2000 2002 2003
Documenting Changes in VBA Code Your company may be regulated by requirements that it document any changes to the macros in an Excel worksheet. Your options in automatically documenting such changes are virtually non-existent, but you are not out of luck. This tip discusses ways you can track what changes are made in your code. Microsoft Excel versions: 97 2000 2002 2003 2007
DOS From Macros Do you need to execute some DOS (command line) commands from within a macro? You can do so by using the Shell command, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Easily Changing the Default Drive and Directory Need to change the drive and directory considered the “default” by the operating system? This tip explains how easy it is to do this within a macro. Microsoft Excel versions: 97 2000 2002 2003 2007
Editing Macros If you start using macros to process data in Excel, you’ll eventually have to edit those macros. You can also display macros developed by other people (or created with the Macro Recorder) to see how particular actions are performed in the VBA code. This tip shows just how easy it is to display and edit a macro. Microsoft Excel versions: 97 2000 2002 2003
Engineering Calculations In an engineering or scientific environment, it is not unusual to need data "normalized" in some manner. This tip examines a couple of different ways you can normalize your data, including a method that adds units and the appropriate prefixes for those units. Microsoft Excel versions: 97 2000 2002 2003
Fixing Macro Button Behavior in Protected Worksheets If circumstances are just right, you can end up with an ineffective macro button when you protect a worksheet. This tip explains the circumstances, what causes the problem, and how you can go about fixing it. Microsoft Excel versions: 97 2000 2002 2003
Forcing a Macro to Run When a Worksheet is Recalculated Normally a macro is only calculated when you specifically tell Excel to calculate it. Some macros need to be calculated whenever your worksheet is recalculated. This won’t happen unless you include a very specific command within the body of your macro. Microsoft Excel versions: 97 2000 2002 2003 2007
Generating Random Testing Data Testing is an intrinsic part of developing any software or any worksheet that will be used by others. If you need to create data to use in your testing, the information (and macros) in this tip will be useful. Microsoft Excel versions: 97 2000 2002 2003
Generating Unique Numbers for Worksheets You may need to automatically generate unique numbers when you create new worksheets in a workbook. Here’s a couple of easy ways to do it. Microsoft Excel versions: 97 2000 2002 2003 2007
Getting Big Macros to Run Troubleshooting an Excel macro when it causes the entire computer to freeze. Microsoft Excel versions: 97 2000 2002 2003
Getting Rid of Alphabetic Characters If you have some data that has a combination of alphabetic and other characters, and you want to get rid of only the alphabetic characters, you could be facing a huge editing job. Of course, you could rely upon a macro to do the editing for you, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Getting Rid of the "Enable Macros" Notice Do you get tired of the dialog box that says “do you want to enable macros” that is displayed when you open a workbook. You can get rid of it by getting rid of the modules that used to hold your long-gone macros. Microsoft Excel versions: 97 2000 2002 2003 2007
Getting User Input in a Dialog Box Want to get some input from the users of your workbooks? You can do it by using the InputBox function in a macro. Microsoft Excel versions: 97 2000 2002 2003 2007
Inserting Worksheet Values with a Macro Placing values into a cell with a macro is easy when you use the Value property. This tip demonstrates how you can use the Value property in your own macros. Microsoft Excel versions: 97 2000 2002 2003
Item Not Available in Library When sharing workbooks with others, you may find that the macros in those workbooks may not work as you expect. This tip focuses on one particularly common problem that you’ll need to address. Microsoft Excel versions: 97 2000 2002 2003 2007
Macro Runs Slowly, but Steps Quickly When you have a macro that processes a huge amount of data, it can seem like it takes forever to finish up. These slowdowns can be aggravating, but part of developing macros is figuring out where those bottlenecks occur. This tip provides a few ideas you can use. Microsoft Excel versions: 97 2000 2002 2003 2007
Macro Slows Down on More Powerful Machine Macros can run differently on different machines. This fact can be painfully obvious if a macro runs slower on a machine that you thought was faster. This tip explains how these sorts of discrepancies can happen, and some tips about what you can do to speed things up. Microsoft Excel versions: 97 2000 2002 2003
Macros in Template Files People often place macros in template files to perform any number of tasks. This tip describes a situation where the link between a toolbar button and a macro was broken when a new document was created from a template. The problem was corrected by double-checking where the toolbar button pointed when referencing the macro. Microsoft Excel versions: 97 2000 2002 2003
Making Common Functions Available to Others When you use macros to create functions, you might want to share those functions with others—particularly if they perform tasks that are essential to your business. There are a couple of ways you can share them, as this tip describes. Microsoft Excel versions: 97 2000 2002 2003
Mouse Click Event in VBA Need to know if a particular cell is clicked with the mouse? Excel has no particular event handler for clicking in this way, but you could use one of the other event handlers provided by the program. Microsoft Excel versions: 97 2000 2002 2003 2007
Moving Macros from the Personal Workbook Need to move a macro out of your Personal.xls workbook and into a regular workbook? You can do it using familiar editing techniques, as illustrated in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Noting When a Workbook was Changed You may want to keep track of when changes were last made to a workbook, particularly if the workbook is accessible to multiple people who may change it. This tip discusses a couple of ways you can keep track of such information. Microsoft Excel versions: 97 2000 2002 2003
Out of Memory Errors when Accessing the VBA Editor It can be frustrating when you get error messages doing something that you previously did with no errors. If you get an out of memory error when pulling up the VBA editor, this tip may help you track down the cause. Microsoft Excel versions: 97 2000 2002 2003 2007
Pasting Without Updating References Do you need to paste formulas without updating the references in whatever you are pasting? You can accomplish this, depending on what you are pasting and where you are pasting it. Microsoft Excel versions: 97 2000 2002 2003 2007
Pausing Macros for User Input Your macros may need to get some input from whoever is using those macros. The best way to get that input is through the use of the MsgBox and InputBox functions, described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Playing with a Full Deck Do you have a range of cells that you need to populate with a series of numbers in random order? If so, this is where a macro can come in handy. In fact, the macro in this tip will help you to get the desired results as quickly as possible. Microsoft Excel versions: 97 2000 2002 2003
Pulling Apart Cells The Text to Columns tool is a great boon for analyzing textual data in a worksheet. You can use the tool to strip text into component parts that you can work with easier. This tip explains how to use the tool and introduces a macro you can use when the tool won’t work just the way you want it to. Microsoft Excel versions: 97 2000 2002 2003 2007
Putting an X in a Clicked Cell Need to click on a cell and have it replaced with an “X”? Macros make it easy to do, as illustrated in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Quickly Dumping Array Contents One of the core skills in VBA is the ability to use and manipulate variables. This tip explains how you can wipe out the contents of a variable array easily. Microsoft Excel versions: 97 2000 2002 2003 2007
Relative References when Recording Macros When you record macros, Excel normally assumes that any movements you make are to be interpreted as absolute movements. That can cause a few problems when you later play back the macro. To get around this, learn to use the Relative References tool, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003
Removing a Macro from a Shortcut Key When you create a macro, you can add a shortcut key to the macro. Simply use the shortcut, and the macro is executed. If you want to later disassociate the shortcut from the macro, you’ll need the information provided in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Removing All Macros Macros are stored as part of a workbook so that they are always available when you have the workbook open. If you want to get rid of the macros in a workbook, there are a couple of ways you can do it. This tip examines two quick ways to get rid of the macros. Microsoft Excel versions: 97 2000 2002 2003 2007
Removing Pictures for a Worksheet in VBA If you are having a problem deleting pictures using a macro, it could be due to either bad syntax or different groupings of the images. This tip discusses both causes and what you can do about them. Microsoft Excel versions: 97 2000 2002 2003 2007
Renaming a Macro When you first create a macro, you assign a name to it. Later you can change the name, but the steps you follow are not exactly intuitive. This tip presents the easiest way to change a macro’s name. Microsoft Excel versions: 97 2000 2002 2003
Reversing Cell Contents Need to reverse what is in a cell? Use a quick user-defined function, presented in this tip, to accomplish the feat. Microsoft Excel versions: 97 2000 2002 2003
Running a Macro When a Worksheet is Deactivated You can easily configure Excel so that it runs a specific macro whenever a worksheet is deactivated. Just follow the easy steps in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Running Macros in the Background Got a long-running macro that seems to be tying up your machine? You can safely allow Excel macros to work away in a background window while you continue to work on other tasks in a different widow. Microsoft Excel versions: 97 2000 2002 2003 2007
Running Macros on Hidden Worksheets You can format a worksheet so that it is hidden from someone looking through the worksheets in a workbook. This means, however, that you cannot access information on that worksheet in a macro. This tip explains how to get around the problem. Microsoft Excel versions: 97 2000 2002 2003 2007
Saving a Workbook in a Macro Does your macro need to make sure that the workbook being processed is saved to disk? You can add the saving capability by using a single code line. Microsoft Excel versions: 97 2000 2002 2003 2007
Saving Changes when Closing If your macro closes workbooks, you’ll want to make sure that it will save any changes you made to the workbook. Here’s how to do it. Microsoft Excel versions: 97 2000 2002 2003 2007
Saving Non-Existent Changes Do you get frustrated when Excel asks if you want to save your changes when closing a workbook in which you made no changes? It is helpful to understand not only why Excel displays this prompt, but how you can get rid of it. Microsoft Excel versions: 97 2000 2002 2003 2007
Selecting a Cell in the Current Row When creating a macro, you may wonder how you can access cells in the same row as the currently selected cell. The techniques covered in this tip can save you lots of time and make your macros much more powerful. Microsoft Excel versions: 97 2000 2002 2003
Selecting a Specific Cell in a Macro How you select a specific cell in a worksheet depends on many factors. This tip examines how you can select a specific cell in a specific worksheet of a specific workbook. Use the wrong approach, and you end up with an error; use the techniques here and you can enjoy success. Microsoft Excel versions: 97 2000 2002 2003
Selecting Columns in VBA when Cells are Merged If you manually select an entire column, and there are some cells in that column that are merged with cells in an adjacent column, Excel sort of “skips” the merged cells in the selection. Not so in VBA, where selecting the entire column results in selecting all the columns affected by the merged cells. This tip explains why this happens and presents some other options about how to work with entire columns that contain merged cells. Microsoft Excel versions: 97 2000 2002 2003
Setting Row Height in a Macro Using the RowHeight property, your macro can adjust the height of any row in a workbook. This tip explains how to use the property properly. Microsoft Excel versions: 97 2000 2002 2003 2007
Shortcut Key for Format Painter The Format Painter tool is very handy when you want to quickly duplicate formatting form one place to another. The tool virtually requires the use of the mouse, however, as there is no built-in shortcut to use it. This tip describes some of the ways you can use the Format Painter or copy formatting by using the keyboard only. Microsoft Excel versions: 97 2000 2002 2003 2007
Specifying a Paper Tray in a Macro Different printers have different capabilities. One common option on printers is a multitude of paper trays. Specifying which paper tray that Excel should use for printing is next to impossible to do, but the ideas in this tip can help achieve your desired results. Microsoft Excel versions: 97 2000 2002 2003
Splitting Information into Rows If you have data stored in multiple lines in a single cell, you might want to expand that data so that it actually appears on multiple rows. There is no built-in function to do this in Excel, but you can create one using the macros highlighted in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Swapping Two Numbers Need to exchange what is stored in two variables in a macro? It’s easy to do if you apply the technique in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Testing for an Empty Worksheet If you using a macro to print out a series of worksheets, you may want a way to determine if a particular worksheet contains information before printing it. This tip examines several techniques you can use to determine if a worksheet is empty or not. Microsoft Excel versions: 97 2000 2002 2003 2007
Understanding Phantom Macros Knowing how Excel sees macros and how to fix phantom macros. Microsoft Excel versions: 97 2000 2002 2003
Understanding the Select Case Structure The Select Case programming structure allows you to create a framework of conditional code that will be executed only under the conditions you specify. This tip explains how to build your Select Case structure. Microsoft Excel versions: 97 2000 2002 2003
Understanding the While...Wend Structure The programming language in Excel (VBA) provides some powerful structures that allow you to repeat portions of your program or modify the order in which statements are processed. This tip takes a look at the While...Wend structure, which allows a programming block to be repeated as long as a condition (that you specify) is true. Microsoft Excel versions: 97 2000 2002 2003
Unhiding or Listing All Objects In complex workbooks with lots of objects, it is easy to “lose” an object so that you cannot select it. The macro techniques used in this tip allow you to examine or display all of the objects in a workbook, including those that were previously unreachable. Microsoft Excel versions: 97 2000 2002 2003
Updating Automatically When Opening Under Macro Control When you open a workbook that contains links to another data source, Excel asks if you want to update those links. This is great if you are opening the workbook manually, but not so great if the workbook is being opened by a macro. This tip discusses ways you can turn off the prompting so the macro will open and process the workbook with the delay. Microsoft Excel versions: 97 2000 2002 2003
Using Message Boxes When creating a macro, one of the ways you can communicate with users is through the use of a message box. This tip explains what message boxes are and how to implement them in your own macros. Microsoft Excel versions: 97 2000 2002 2003
Using Old Lotus Macros Using a Lotus 1-2-3 macro in Excel. Microsoft Excel versions: 97 2000 2002 2003
Using SUM In a Macro If you need to use the SUM worksheet function from within a macro, you can easily do it by using the techniques discussed in this tip. You can even use the function with a variable number of cells in a column. Microsoft Excel versions: 97 2000 2002 2003 2007
Waiting for Update Completion If you use Excel to grab data from an external source, you may notice that the macro doing the data grabbing doesn’t always wait for the data to be ready. This tip explains why this occurs. Microsoft Excel versions: 97 2000 2002 2003 2007
Workbook Events You can program Excel so that when specific events happen, your macro is executed. Your event handlers can react to almost 30 different events relative to a workbook, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Working While a Macro is Running If you have a macro that takes a long time to process a workbook, you might want to continue working in Excel while the macro is busy. Here’s a way you can accomplish your desire. Microsoft Excel versions: 97 2000 2002 2003 2007
Worksheet Events You can program Excel so that when specific events happen, your macro is executed. Your event handlers can react to a variety of events relative to a worksheet, as described in this tip. Microsoft Excel versions: 97 2000 2002 2003 2007
Have thousands of ExcelTips at your fingertips, on your own system. Answer your own questions or help support others. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site