XL98: Value Property Unchanged in For Each Loop with Variant Type (191176)
The information in this article applies to:
- Microsoft Excel 98 Macintosh Edition
This article was previously published under Q191176 SYMPTOMS
When you use a For Each loop in a Visual Basic for Applications macro, the
macro may run without error, but values changed in the For Each loop may
not actually change.
CAUSE
Values changed in a For Each loop may only appear to be changed during the
running of the macro if the following conditions are true:
- You are changing the default value property of an object or an element
in an array.
-and-
- The loop control variable is a Variant data type.
This behavior is by design of Microsoft Excel.
WORKAROUND
To work around this problem, use either of the following methods:
- Use the Dim statement to declare the control variable of type Object
rather than a Variant data type.
-or-
- Use an explicit default value property in your macro code.
REFERENCES
For more information about the For Each loop, from the Visual Basic Editor,
click the Office Assistant, type for each, click Search, and then click
to view "For Each...Next Statement."
NOTE: If the Assistant is hidden, click the Office Assistant button on the
Standard toolbar. If the Assistant is not able to answer your query, please
see the following article in the Microsoft Knowledge Base:
176476 OFF: Office Assistant Not Answering Visual Basic Questions
For additional information about getting help with Visual Basic for
Applications, please see the following article in the Microsoft Knowledge
Base:
163435 VBA: Programming Resources for Visual Basic for Applications
Modification Type: | Minor | Last Reviewed: | 9/12/2006 |
---|
Keywords: | kbdtacode kbprb KB191176 |
---|
|