Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

XL2000: How to Programmatically Insert Blank Rows in a Worksheet


View products that this article applies to.

Summary

In Microsoft Excel 2000, you can use a Microsoft Visual Basic for Applications macro to programmatically insert a blank row between every row of data on your worksheet. The example in this article contains a sample macro that performs this task.

↑ Back to the top


More information

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Sample Macro

To insert a blank row between every row of data, follow these steps:
  1. Start Excel 2000, and then create the following worksheet:
       A1:    222
       A2:    333
       A3:    444
       A4:    555
       A5:    666
    					
  2. Press ALT+F11 to start the Visual Basic Editor.
  3. On the Insert menu, click Module.
  4. In the module sheet, type or paste the following code:
    Sub Insert_Blank_Rows()
    
       'Select last row in worksheet.
       Selection.end(xldown).select
    
       Do Until ActiveCell.row = 1
          'Insert blank row.
          ActiveCell.EntireRow.Insert shift := xldown
          'Move up one row.
          ActiveCell.Offset(-1,0).Select
       Loop
    
    End Sub
    					
  5. Press ALT+F11 to return to Excel.
  6. Select cell A1 or any cell that contains data.
  7. Press ALT+F8 to open the Macro dialog box.
  8. In the Macro name list, click Insert_Blank_Rows, and then click Run. The macro returns the following values:
       A1:    222
       A2:
       A3:    333
       A4:
       A5:    444
       A6:
       A7:    555
       A8:
       A9:    666
    					
NOTE: If you select a blank cell, Excel places a blank between all 65,000 possible rows on the worksheet. If this happens, press ESC to stop the macro, and then select any cell with data in it and repeat step 7.

↑ Back to the top


Keywords: KB213318, kbprogramming, kbinfo, kbhowto, kbdtacode

↑ Back to the top

Article Info
Article ID : 213318
Revision : 8
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 409