Home

Two similar VBA Excel code

chancelin
Contributor

Here are two VBA property codes on the RANDE that mean the same thing:

Range("A1:A10").Value = 99

Range(Cells(1, 1), Cells(10, 10)).Value = 99

In which case the second one really had to be used?

In other words, in which case the property Cells, referring to the RANGE is really used?

1 Reply

I am assuming the second line was to read as below if they were to match.

 

Range(Cells(1, 1), Cells(10, 1)).Value = 99

Using Range with Cells would typically be used when one of the properties of Cells is to be a variable, easy enough to do   "A" & i   however if we wanted a variable for the row number but it becomes messy if we want the Column letter to be a variable, much easier to work with integers as variables using Cells with Range vs. using letters with Range without Cells.