Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company.
Learn more about Allen...
Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Inserting and Copying Rows.
As you are editing worksheets, you may notice that some of your work is done based on work you have done before. For instance, you may have a row of data that you entered in a previous Excel session. In this session, you need to copy that row of data and use it as the basis for your new data, but with a few changes.
In such a situation, it would be nice to have a quick way to enter a blank row after the current row, and copy the data in the current row to the new blank row. There are no intrinsic commands in Excel to do this, but a macro can do it very handily. Consider the following example:
Sub InsertCopyRow1() ActiveCell.EntireRow.Select Selection.Copy Selection.Insert Shift:=xlDown End Sub
In order to use the macro, all you need to do is select a cell in any row. When the macro is run, a duplicate of the current row is inserted just below the row you are in.
The only problem with this solution is that it leaves the Excel interface a bit "messy" (for lack of a better word). When completed, a complete row is still selected, and the new row has the "marching ants" marquee around it.
This problem can be overcome by including commands to collapse the selection and move it to a desired location. Another way is to simply use a different macro that relies on different VBA commands. The following macro will also insert and copy a row, but it leaves the cell that you selected active:
Sub InsertCopyRow2() ActiveCell.Offset(1, 0).EntireRow.Insert ActiveCell.EntireRow.Copy ActiveCell.Offset(1, 0).EntireRow End Sub
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2042) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Inserting and Copying Rows.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!