Applying to Cells and Ranges
One of the basic actions in Microsoft Excel is applying to cells and ranges on which we wish to conduct various processing.
A range can be a single cell, a sequence of cells, a column, a row, or even the entire worksheet.
The main commands related to ranges are:
- Range
- ActiveCell
- Selection
Examples:
Range(“b5”).Select
Selecting the cell B5 (Please note the quotation marks surrounding the cell name)
Range(“b5”, “c10”).Select
Selecting the range B5:C10
Range(“b5”, “c10”).Select
Another way of applying to a range is by selecting its ends
Range(“b5, c10”).Select
Selecting non-sequential ranges
Range(ActiveCell, “d3”).Select
Selecting a range from the Active Cell to cell D3
Range(“first”).Select
Selecting a range by using the name “first” that was given earlier to a cell or to a range of cells in the worksheet
Range(“first”, “Second”).Select
Selecting a range by using two names that were given earlier to two cells in the worksheet
Selection.Interior.Color = vbGreen
Coloring in green a range of cells that were selected earlier in the worksheet/code
Note:
Although it seems that the command range(“c2”).select is selecting cell C2,
in fact it is selecting the cell in the second row and the third column, as the default reference point is cell A1.
Therefore, the next command:
Range(“b5”).Range(“a2”).Select
Select the cell in the second row and the first column, according to the reference point B5, which means cell B6.
If you are intrigued and want to learn more,
you can do it with my “Excel VBA – For Non Programmers” Book on amazon
You can also buy it as a PDF,
at a small 6.73 investment