Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default formula in vba


Range("a10") = "= a2 + a3 + a5"
Range("a12").Formula = "=a2+a3+a5"
both appear to give correct result. Then on what conditions the property
"formula " is to be used.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default formula in vba

Whe n you don't spesify what property to be used, the object's default will
be used. For cells that's Value. But what happens here is that Excel
recognizes a value starting with = to be a formula, so she makes it a
formula.

So in this case it makes no difference for entry, but for retrieval and
manipulation it's crucial. Note the last part of this little demo:

Sub test()
MsgBox "Will execute: Range(""a10"") = ""= a2 + a3 + a5"""
Range("a10") = "= a2 + a3 + a5"

MsgBox "Range(""a10""): " & Range("a10"), , _
"Not what you said a10 it should be ?"

MsgBox "Range(""a10"").Formula: " & _
Range("a10").Formula & Chr(10) & _
"Range(""a10"").Value: " & _
Range("a10").Value, , _
"Note the difference:"


MsgBox "Now let's do something stupid:" & Chr(10) & _
"Will execute: Range(""a10"") = Range(""a10"")"

Range("a10") = Range("a10")

MsgBox "Range(""a10"").Formula: " & _
Range("a10").Formula & Chr(10) & _
"Range(""a10"").Value: " & _
Range("a10").Value, , "Formula is destroyed:"
End Sub
--
HTH. Best wishes Harald
Excel MVP
Followup to newsgroup only please

"R.Venkataraman" skrev i melding
...

Range("a10") = "= a2 + a3 + a5"
Range("a12").Formula = "=a2+a3+a5"
both appear to give correct result. Then on what conditions the property
"formula " is to be used.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default formula in vba

thanks.

"Harald Staff" wrote in message
...
Whe n you don't spesify what property to be used, the object's default will
be used. For cells that's Value. But what happens here is that Excel
recognizes a value starting with = to be a formula, so she makes it a
formula.

So in this case it makes no difference for entry, but for retrieval and
manipulation it's crucial. Note the last part of this little demo:

Sub test()
MsgBox "Will execute: Range(""a10"") = ""= a2 + a3 + a5"""
Range("a10") = "= a2 + a3 + a5"

MsgBox "Range(""a10""): " & Range("a10"), , _
"Not what you said a10 it should be ?"

MsgBox "Range(""a10"").Formula: " & _
Range("a10").Formula & Chr(10) & _
"Range(""a10"").Value: " & _
Range("a10").Value, , _
"Note the difference:"


MsgBox "Now let's do something stupid:" & Chr(10) & _
"Will execute: Range(""a10"") = Range(""a10"")"

Range("a10") = Range("a10")

MsgBox "Range(""a10"").Formula: " & _
Range("a10").Formula & Chr(10) & _
"Range(""a10"").Value: " & _
Range("a10").Value, , "Formula is destroyed:"
End Sub
--
HTH. Best wishes Harald
Excel MVP
Followup to newsgroup only please

"R.Venkataraman" skrev i melding
...

Range("a10") = "= a2 + a3 + a5"
Range("a12").Formula = "=a2+a3+a5"
both appear to give correct result. Then on what conditions the property
"formula " is to be used.







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Commenting custom formula fields/formula on formula editor Muxer Excel Programming 2 July 24th 03 01:02 AM


All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"