The information in this article applies to:
SUMMARYThe way that Microsoft Excel 98 Macintosh Edition deletes cells in a For Each...Next loop in a Microsoft Visual Basic for Applications Sub procedure differs from the way that earlier versions of Microsoft Excel delete cells. This article describes the differences and includes a Visual Basic Sub procedure example that deletes cells in a loop. MORE INFORMATIONMicrosoft 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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.asp Typing Sample DataTo use the macro in this article, type the following sample data in a worksheet:
Typing the Sample MacroIn a new macro module, type the following macro:
Behavior of the Sample Macro in Microsoft Excel 98When you run the macro DeleteCells in Microsoft Excel 98, only rows 3, 6, and 8 are deleted. Although rows 4 and 9 contain an "x" in column A, the macro does not delete the rows. The results of running the macro in Microsoft Excel 98 are the following:
When Microsoft Excel deletes row 3, all cells move up one row. For example,
cell A3 assumes the contents of cell A4, cell A4 assumes the contents of
cell A5, and so forth. After the For Each...Next loop evaluates a cell, it
evaluates the next cell; thus, when cells are shifted, they may be skipped
by the loop.
Behavior of the Sample Macro in Microsoft Excel 5.0When you run the macro DeleteCells in Microsoft Excel 5.0, the macro deletes all rows that contain an "x." The results of the macro in Microsoft Excel 5.0 are the following:
When row 3 is deleted, all cells move up one row; and cell A3 assumes the
contents of cell A4, cell A4 assumes the contents of cell A5, and so forth.
However, unlike the behavior of the loop in Microsoft Excel 98, when the
For Each...Next loop evaluates a cell in Microsoft Excel 5.0, it
reevaluates the cell if it is deleted in the loop; thus, the cells are not
skipped.
Recommended Method for Using a Loop to Delete CellsUse the following macro when you want to use a loop to delete cells:
The results of this macro in Microsoft Excel 98 and earlier versions are as
follows:
Additional Method for Using a Loop to Delete CellsThis is an alternate method to the method shown above. It produces the same results.
REFERENCES
For more information about looping in a macro, from the Visual Basic
Editor, click the Office Assistant, type looping, click Search, and then
click to view "Looping Through Code."
Q176476 OFF: Office Assistant Not Answering Visual Basic Questions Additional query words: 8.0 8.00 XL98
Keywords : kbprg kbdta kbconversion xlvbainfo OffVBA xlvbmigrate |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |