0% found this document useful (0 votes)
49 views

Range: Using The Range Collection

This document discusses Excel range objects and properties. It explains that a range can represent a single cell, row, column, selection of contiguous cells, or 3D range. It describes the Range, Cells, Offset, and Union properties/methods that return Range objects for single cells or ranges. It provides examples of using these properties/methods to select ranges, get/set cell values, and offset from a range.

Uploaded by

av_meshram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLS, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Range: Using The Range Collection

This document discusses Excel range objects and properties. It explains that a range can represent a single cell, row, column, selection of contiguous cells, or 3D range. It describes the Range, Cells, Offset, and Union properties/methods that return Range objects for single cells or ranges. It provides examples of using these properties/methods to select ranges, get/set cell values, and offset from a range.

Uploaded by

av_meshram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLS, PDF, TXT or read online on Scribd
You are on page 1/ 8

Range

Represents a cell, a row, a column, a selection of cells containing one or more contiguous blocks of cells, or a 3-D range.
Using the Range Collection
The following properties and methods returns a Range object:
Range property
Cells property
Offset property
Union method

Range Property
Use Range(arg), where arg names the range, to return a Range object that represents a single cell or a range of cells. The f
in cell A5.
Worksheets("Sheet1").Range("A5").Value = Worksheets("Sheet1").Range("A1").Value

If you use a text argument for the range address, you must specify the address in A1-style notation (you cannot use R1C1-st

Cells Property
Use Cells(row, column) where row is the row index and column is the column index, to return a single cell. The following exa
Worksheets(1).Cells(1, 1).Value = 24

Although you can also use Range("A1") to return cell A1, there may be times when the Cells property is more convenient be
column. Although you could use Visual Basic string functions to alter A1-style references, it's much easier (and much better p
notation.

Use expression.Cells(row, column) , where expression is an expression that returns a Range object, and row and column a
range, to return part of a range. The following example sets the formula for cell C5.
Worksheets(1).Range("C5:C10").Cells(1, 1).Formula = "=Rand()"

Range and Cells


Use Range(cell1, cell2), where cell1 and cell2 are Range objects that specify the start and end cells, to return a Range obje
style for cells A1:J10.
With Worksheets(1)
.Range(.Cells(1, 1), _
.Cells(10, 10)).Borders.LineStyle = xlThick
End With

Notice the period in front of each occurrence of the Cells property. The period is required if the result of the preceding With
property in this case, to indicate that the cells are on worksheet one (without the period, the Cells property would return ce

Offset Property
Use Offset(row, column), where row and column are the row and column offsets, to return a range at a specified offset to an
the cell three rows down from and one column to the right of the cell in the upper-left corner of the current selection. You can
so you must first activate the worksheet.
Worksheets("Sheet1").Activate
'Can't select unless the sheet is active
Selection.Offset(3, 1).Range("A1").Select

so you must first activate the worksheet.


Worksheets("Sheet1").Activate
'Can't select unless the sheet is active
Selection.Offset(3, 1).Range("A1").Select

us blocks of cells, or a 3-D range.

single cell or a range of cells. The following example places the value of cell A1

le notation (you cannot use R1C1-style notation).

eturn a single cell. The following example sets the value of cell A1 to 24.

Cells property is more convenient because you can use a variable for the row or
, it's much easier (and much better programming practice) to use the Cells(1, 1)

ange object, and row and column are relative to the upper-left corner of the

nd end cells, to return a Range object. The following example sets the border line

d if the result of the preceding With statement is to be applied to the Cells


d, the Cells property would return cells on the active sheet).

rn a range at a specified offset to another range. The following example selects


ner of the current selection. You cannot select a cell that isnt on the active sheet,

Suma

Function with the whole range as a parameter

Procedure detects the end of the range

Product
3
4
5
6
7
3
7
7
4
6

3
4
5
6
7
3
7
7
4
6

#VALUE!

#VALUE!

Calculate

Calculate

Random Numbers
0.705548
0.414033
0.053505
0.986093
0.575184
0.401374
0.186014
0.627642
0.677948
0.390291
0.506087
0.105453
0.454208
0.207627
0.272942
0.340607
0.634372
0.13042
0.996771
0.509068

0.533424
0.862619
0.592458
0.910964
0.100052
0.27828
0.583359
0.428456
0.502454
0.364995
0.390471
0.331694
0.357023
0.329736
0.673647
0.044934
0.410037
0.028886
0.339806
0.227782

0.579519
0.79048
0.4687
0.226866
0.103023
0.160442
0.080715
0.097974
0.513737
0.489895
0.107375
0.12825
0.149981
0.095429
0.256629
0.482428
0.960423
0.345392
0.495211
0.619188

0.289562
0.373536
0.298165
0.695116
0.798884
0.162822
0.457971
0.56104
0.46298
0.155663
0.783995
0.000241
0.704396
0.589793
0.089897
0.206017
0.114623
0.547669
0.412968
0.48983

0.301948
0.961953
0.622697
0.980003
0.28448
0.646587
0.90573
0.694485
0.353473
0.474459
0.459641
0.536794
0.928786
0.169873
0.030951
0.864534
0.923445
0.922955
0.695282
0.680819

0.77474
0.871446
0.647821
0.243931
0.045649
0.410073
0.261368
0.913718
0.404834
0.257268
0.753688
0.657055
0.530213
0.927617
0.322718
0.588629
0.62021
0.538246
0.179089
0.8866

Generate Random Numbers

0.014018
0.056237
0.263793
0.533873
0.295773
0.412767
0.785212
0.834817
0.269732
0.628752
0.596095
0.544014
0.089641
0.09793
0.790129
0.754908
0.347726
0.406421
0.422918
0.370515

0.760724
0.949557
0.279342
0.10637
0.382011
0.71273
0.378903
0.022629
0.055593
0.54207
0.83273
0.827412
0.757729
0.443862
0.297258
0.927883
0.149246
0.847246
0.543177
0.302498

0.81449
0.364019
0.829802
0.999415
0.30097
0.326206
0.289665
0.543361
0.243845
0.156302
0.018758
0.081894
0.401842
0.272947
0.235282
0.331017
0.479978
0.826226
0.814664
0.292867

0.709038
0.524868
0.824602
0.676176
0.948571
0.633179
0.919377
0.916164
0.979078
0.938545
0.210369
0.191922
0.461874
0.872547
0.480475
0.542941
0.219409
0.672428
0.540914
0.150311

0.045353
0.767112
0.589163
0.015704
0.979829
0.207561
0.631742
0.430261
0.060916
0.654499
0.073953
0.678913
0.492166
0.750688
0.254602
0.080691
0.993731
0.721895
0.427533
0.529821

CAPM

You might also like