Microsoft KB Archive/213318

= XL2000: How to Programmatically Insert Blank Rows in a Worksheet =

Article ID: 213318

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213318





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.



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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

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:   Start Excel 2000, and then create the following worksheet:   A1:    222 A2:   333 A3:   444 A4:   555 A5:   666  Press ALT+F11 to start the Visual Basic Editor. On the Insert menu, click Module.  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  Press ALT+F11 to return to Excel. Select cell A1 or any cell that contains data.</li> Press ALT+F8 to open the Macro dialog box.</li>  In the Macro name list, click Insert_Blank_Rows, and then click Run. The macro returns the following values: <pre class="fixed_text">  A1:    222 A2: A3:   333 A4: A5:   444 A6: A7:   555 A8: A9:   666 </li></ol>

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.

Additional query words: XL2000

Keywords: kbdtacode kbhowto kbinfo kbprogramming KB213318

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.