Excel Range: Difference between revisions
m (→Last Cell) |
m (→Used Range) |
||
Line 33: | Line 33: | ||
Note that the range does not contain row 1 and column 1!<br /> | Note that the range does not contain row 1 and column 1!<br /> | ||
[[File:Range_UsedRange.jpg]]<br /> | [[File:Range_UsedRange.jpg]]<br /> | ||
<br /> | |||
<syntaxhighlight lang="autoit">$sUpperLeftCell = $oWorkbook.ActiveSheet.UsedRange.Cells(1, 1).Address</syntaxhighlight> | |||
Returns the address of the upper left cell of the used range. In this examle: B2<br /> | |||
<br /> | <br /> | ||
<syntaxhighlight lang="autoit">With $oWorkbook.ActiveSheet | <syntaxhighlight lang="autoit">With $oWorkbook.ActiveSheet |
Revision as of 19:06, 26 May 2015
On this page you will find some special ranges and how to define them in AutoIt.
As input file I will use the following Excel workbook. All cells which have a value now or had a value before (means: all cells which had been touched by the user or a script) are displayed in grey.
All examples show cells of the selected range in yellow.
Current Region
$oRange = $oWorkBook.Activesheet.Range("B4").CurrentRegion
The current region is a range bounded by any combination of blank rows and blank columns.
Note that cell B6 is not part of the region. The cell has been touched before but now is blank and hence bounds the region.
Empty Cells
$oRange = $oWorkbook.ActiveSheet.UsedRange.SpecialCells($xlCellTypeBlanks)
Marks all empty cells in the specified range.
Entire Row / Entire Column
$oRange = $oWorkBook.Activesheet.Range("B2").EntireRow
Selects the entire row(s) of the specified range.
Use method "EntireColumn" to select the columns for the specified range.
Last Cell
$oRange = $oWorkbook.ActiveSheet.UsedRange.SpecialCells($xlCellTypeLastCell)
Returns the last used cell (bottom right) in the specified range.
External Link: Excel Ranges: Finding the Last Cell in a Range
Used Range
$oRange = $oWorkBook.Activesheet.UsedRange
Selects all cells which have a value now or had a value before (means: all cells which had been touched by the user or a script).
Note that the range does not contain row 1 and column 1!
$sUpperLeftCell = $oWorkbook.ActiveSheet.UsedRange.Cells(1, 1).Address
Returns the address of the upper left cell of the used range. In this examle: B2
With $oWorkbook.ActiveSheet
$oRangeLast = .UsedRange.SpecialCells($xlCellTypeLastCell)
$oRange = .Range(.Cells(1, 1), .Cells($oRangeLast.Row, $oRangeLast.Column))
EndWith