Cyberdude
10-09-2005, 12:12 PM
I have been trying to come up with the rules for using the ?End? property (End(xlUp), End(xlToRight), etc.), and I?m having trouble generalizing. I used a range that looks like:
cols-> K L M N O P Q ? IV
vals-> b b M N O P b
where ?b? is a blank, letters shown are the columns, and using row 5, then executed the following statements:
Range("K5").End(xlToRight).Select?...selects M5??.K L M N O P Q ? IV
Range("L5").End(xlToRight).Select?...selects M5??.K L M N O P Q ? IV
Range("M5").End(xlToRight).Select?...selects P5??.K L M N O P Q ? IV
Range("N5").End(xlToRight).Select?...selects P5??.K L M N O P Q ? IV
Range("P5").End(xlToRight).Select?...selects IV5? .K L M N O P Q ?IV
The Help writeup says End ?Returns a Range object that represents the cell at the end of the region that contains the source range.? My tests don?t seem to confirm this statement.
When I begin with a cell that contains a null/blank value (column K or L), the statement selects ?M?, which is not in the same region as the source range. Help defines a region as ?a range bounded by any combination of blank rows and blank columns.? With this definition of region, then it would seem that columns K and L aren?t in a region.
Next, when I begin with the cell at the end of the region (?P?), it selects the end of the following series of blanks. I would have expected it to select itself, since P is the end of the region that contains the source range.
Finally, Help gives the following example which ?extends the selection from cell B4 to the last cell in row four that contains data?.
Range("B4", Range("B4").End(xlToRight)).Select
When I ran this example I got the same results as when I ran the following statement:
Range("B4").End(xlToRight)).Select
From the description, I assumed that instead of selecting one cell it would select the whole range from ?B4? to the end of the region. It didn?t seem to do that. It just selected the cell at the end of the region.
cols-> K L M N O P Q ? IV
vals-> b b M N O P b
where ?b? is a blank, letters shown are the columns, and using row 5, then executed the following statements:
Range("K5").End(xlToRight).Select?...selects M5??.K L M N O P Q ? IV
Range("L5").End(xlToRight).Select?...selects M5??.K L M N O P Q ? IV
Range("M5").End(xlToRight).Select?...selects P5??.K L M N O P Q ? IV
Range("N5").End(xlToRight).Select?...selects P5??.K L M N O P Q ? IV
Range("P5").End(xlToRight).Select?...selects IV5? .K L M N O P Q ?IV
The Help writeup says End ?Returns a Range object that represents the cell at the end of the region that contains the source range.? My tests don?t seem to confirm this statement.
When I begin with a cell that contains a null/blank value (column K or L), the statement selects ?M?, which is not in the same region as the source range. Help defines a region as ?a range bounded by any combination of blank rows and blank columns.? With this definition of region, then it would seem that columns K and L aren?t in a region.
Next, when I begin with the cell at the end of the region (?P?), it selects the end of the following series of blanks. I would have expected it to select itself, since P is the end of the region that contains the source range.
Finally, Help gives the following example which ?extends the selection from cell B4 to the last cell in row four that contains data?.
Range("B4", Range("B4").End(xlToRight)).Select
When I ran this example I got the same results as when I ran the following statement:
Range("B4").End(xlToRight)).Select
From the description, I assumed that instead of selecting one cell it would select the whole range from ?B4? to the end of the region. It didn?t seem to do that. It just selected the cell at the end of the region.