{"id":3478,"date":"2018-11-23T20:23:24","date_gmt":"2018-11-23T20:23:24","guid":{"rendered":"http:\/\/officetuts.net\/excel\/?p=3478"},"modified":"2024-03-30T11:45:15","modified_gmt":"2024-03-30T11:45:15","slug":"cells-and-range-property","status":"publish","type":"post","link":"https:\/\/officetuts.net\/excel\/vba\/cells-and-range-property\/","title":{"rendered":"Cells and Range Property in VBA"},"content":{"rendered":"\n

With the Cells property,<\/strong> you can reference any object inside a worksheet, where you can make changes or retrieve the value.<\/p>\n\n\n\n

This is a somewhat confusing subject. It may seem that Cells is an object, but it\u2019s really not. There is no Cells object in the Excel Object Model. So in order to refer to the specific cells, you can either use the Cells property<\/strong> or the Range<\/strong> property<\/strong>. Each of these objects returns the Range model<\/strong>.<\/p>\n\n\n\n

The main difference between the Range and Cells properties is that with the first one you can refer to one or multiple cells, and with the Cells to only a single cell.<\/p>\n\n\n\n

The Cell property takes one or two parameters. The first one is the row number, and the second one is the column number. If the property takes only one parameter, it represents the column number.<\/p>\n\n\n\n

Cells(row, column)\nCells(column)<\/pre>\n\n\n\n

Let’s take a look at the following example.<\/p>\n\n\n\n

Cells.Item(3, 4).Value = 1\nCells.Item(5).Value = 2<\/pre>\n\n\n\n

Item and Value are the default properties, so you can drop it. This code works exactly the same as the one below. It\u2019s also cleaner and more readable.<\/p>\n\n\n\n

Cells(3, 4) = 1\nCells(5) = 2<\/pre>\n\n\n\n

The first line of this code insert 1 into cell D3<\/strong> (third row and fourth column), and the second line into cell E1<\/strong>.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

You can use Cells with the following objects:<\/p>\n\n\n\n