Article ID: 157412 - Last Review: November 23, 2006 - Revision: 2.4 XL97: Select Method May Select More Cells Than ExpectedThis article was previously published under Q157412 On This PageSYMPTOMS
When you run a Visual Basic for Applications macro that uses the Select
method to select a specific range of cells in Microsoft Excel 97, the macro
may select a larger range of cells than you specified.
CAUSE
This problem may occur when you run a macro that uses the Select method to
select a range of cells and performs an action on the selected cells.
If you programmatically select a merged cell in a range, the selection may be enlarged such that it encompasses the columns and/or rows that are occupied by the merged cell. For example, if the range A2:C2 is merged, the following statement selects cells A1:C10 and not A1:A10 as you might expect: NOTE: In this scenario in Microsoft Excel 97, you cannot select only cells A1:A10 with the mouse. Microsoft Excel automatically extends the selection to include cells B1:C10 because the range A2:C2 is merged. This behavior is by design of Microsoft Excel. WORKAROUNDMicrosoft 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 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (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 (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) To work around this behavior, use one of the following methods. Method 1Apply the property or method to specific a Range object rather than the Selection object if the selection contains merged cells that span cells outside of that specified range.For example, the following macro selects cells A1:A10 and applies a bold font format to the selection: Method 2Another alternative is to check whether merged cells exist in the range prior to performing an action. The following macro determines if there are any merged cells in the range A1:A10 prior to formatting the cells: | Article Translations
|

Back to the top
