ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Brackets [] possibilities ? (https://www.excelbanter.com/excel-programming/298436-brackets-%5B%5D-possibilities.html)

alainB[_17_]

Brackets [] possibilities ?
 
Hi,

If I want to put the number 6 in the cell A1 up to now I was doing i
this way:

Range("A1").Select
ActiveCell.FormulaR1C1 = 6

I learn from one post here that I can do it much more easily this way:

[A1] = 6

As long as I just want to put a specific value in one particular cell
should I do it this way?

Thanks

Alai

--
Message posted from http://www.ExcelForum.com


Frank Kabel

Brackets [] possibilities ?
 
Hi
try
=Range("A1").value=6

--
Regards
Frank Kabel
Frankfurt, Germany


Hi,

If I want to put the number 6 in the cell A1 up to now I was doing it
this way:

Range("A1").Select
ActiveCell.FormulaR1C1 = 6

I learn from one post here that I can do it much more easily this

way:

[A1] = 6

As long as I just want to put a specific value in one particular

cell,
should I do it this way?

Thanks

Alain


---
Message posted from http://www.ExcelForum.com/



alainB[_18_]

Brackets [] possibilities ?
 
Thanks,

But wy not [A1] = 6 ?

Still much shorter!

Alai

--
Message posted from http://www.ExcelForum.com


Chip Pearson

Brackets [] possibilities ?
 
Alain,

In some MS documentation (I forget the URL, probably somewhere in
MSDN), it was noted that using the [] syntax is significantly
slower than using the Range() syntax. I suspect, but don't know
for a fact, that everything inside the [] is unknown to the
compiler at compile time, and has to be resolved at run time.
This causes extra code to be generated at compile time and
executed at run time.

You should never use the syntax in your first example:

Range("A1").Select
ActiveCell.FormulaR1C1 = 6


There is no reason to Select the range before operating upon it,
and Select is an expensive operation. Instead, combine the two
lines in to a single line of code like

Range("A1").Value = 6

Performance issues aside, whether to use the [] syntax is a
matter of personal taste. I don't like it (I'm not sure why I
don't like it, but I don't), so I always use the Range() syntax.
If you read the posts of the professional developers in this
newsgroup, you'll find that nearly everyone uses the Range()
syntax over the [] syntax. However, you are free to develop a
coding style that suits you. Whichever you choose, be consistent;
don't mix and match reference styles.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"alainB " wrote in
message ...
Hi,

If I want to put the number 6 in the cell A1 up to now I was

doing it
this way:

Range("A1").Select
ActiveCell.FormulaR1C1 = 6

I learn from one post here that I can do it much more easily

this way:

[A1] = 6

As long as I just want to put a specific value in one

particular cell,
should I do it this way?

Thanks

Alain


---
Message posted from http://www.ExcelForum.com/




Rob van Gelder[_4_]

Brackets [] possibilities ?
 
You could do it this way and it would be faster than doing .Select

Range("A1").Value = 6 is faster than [A1] = 6 though.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"alainB " wrote in message
...
Hi,

If I want to put the number 6 in the cell A1 up to now I was doing it
this way:

Range("A1").Select
ActiveCell.FormulaR1C1 = 6

I learn from one post here that I can do it much more easily this way:

[A1] = 6

As long as I just want to put a specific value in one particular cell,
should I do it this way?

Thanks

Alain


---
Message posted from http://www.ExcelForum.com/




alainB[_19_]

Brackets [] possibilities ?
 
Thanks Chip and Rob!

Alai

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com