ExcelStudy Notes -Region selection
Preface
The New Year is approaching, and I will write down some of my recent learning content. This is a summary of the work and serves as a memorable souvenir. The New Year has a new atmosphere, and 2009 is destined to be a year full of challenges.
The Excel area selection function is very powerful, which brings a lot of flexibility to programming. This article will record some useful selection methods. In Excel, Range is an important object. It represents a combination of cells. Operations on the Range will affect all the cells it contains, which is much more convenient than one unit.
RangeSelect
Range ("A1") Select 1st rows and 1st Columns
Range ("A1: B5"): select the square area between A1 and B5.
Range ("A1: B5, C1: C10") Select multiple regions
Range ("A: A") or Range ("") Select column A (column 1st)
Range ("A: C") Select column A to column C
[A1: B5] This is a convenient recording method, which is equivalent to Range ("A1: B5 ").
RowsAnd Columns
Used to select rows and columns
Rows (1) first line
Rows select all Rows
Columns (1) or Columns ("A") 1st Columns
CellsUsed to select Cells
Cells (6, 1) contains 6th rows and 1st Cells. The Cell object is returned.
To convert a Cell object to a Range object, use [myCell].
UnionEach Range
Dim myRange as Range
Set myRange = Union (Rows (1), Range ("C: C "))
MyRange. Font. Bold = true
Relative displacement
Is relative to a Range.
MyRange. Offset (1, 3) Select cells in the right 3 columns of the row under myRange.
Obtain the cell value cyclically
For each myCell in Range ("A1: B5 ")
'...
Next myCell