Range object in excel vba represents a cell or group of cells in excel worksheet. Most of time excel user working with cells in excel. Range Object accept single cell or multiple cell name as argument and refer excel worksheet cells from vba code. Range object in macro have many attributes and methods for different purpose, here we write most important property of excel range.

The following examples explain the uses of range in excel vba.

Range("A1").value="Hello"

It will print Hello in cell A1 in working worksheet

Range("A1:A10").value="Hello"

It will print Hello in cells A1:A10 in working worksheet

Range("C5,D2,E3").value="Hello"

It will print Hello in different cells C5, D2, and E3 in working worksheet

worksheets("sheet2").Range("C1:C5").value="Hello"

It will print Hello in cells C1 to C5 in worksheet 2
Example :

public sub range_example()
	Range("A1").value="Hello"
	Range("A1:A10").value="Hello"
	Range("C5,D2,E3").value="Hello"
        worksheets("sheet2").Range("C1:C5").value="Hello"
end sub

 

Range Object in Excel VBA

Leave a Reply

Your email address will not be published. Required fields are marked *