user3858
user3858

Reputation: 129

why use cells.value in vba? I tried to use cells without value, it also worked

For the two following lines,

Sheet1.Cells(1,1)=7
Sheet1.Cells(2,1).value=7

These two lines of codes works exactly the same. Why do we even use Cells.value then?

Upvotes: 0

Views: 2488

Answers (1)

Degustaf
Degustaf

Reputation: 2670

TL;DR To not be ambiguous

When You write Sheet1.Cells(1,1) you are receiving a range object. The default property for that object is Value, so when you try to write to that range, it defaults to the value property. Using the Value property explicitly can prevent confusion later on, particularly if you are also using other properties of that range, such as Formula, FormulaR1C1, Value2, ...

Upvotes: 2

Related Questions