为什么使用Range.Formula在VBA for Excel 2003而不是Range.Value? [英] Why use Range.Formula in VBA for Excel 2003 instead of Range.Value?

查看:129
本文介绍了为什么使用Range.Formula在VBA for Excel 2003而不是Range.Value?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么在Excel 2003的VBA代码中,我们甚至需要使用 Range.Formula 将公式写入单元格只需使用 Range.Cell ?他们都将字符串写入到成为论坛的单元格中,该公式可以(从我测试过的)中。

  ActiveCell。 Value == If(True,yesno)

  ActiveCell.Formula == If(True,yes,no)

为我做同样的事情(当我选择一个单元格并单独执行上述每个代码段时)细胞)。他们都在单元格中显示是值,当我点击查看每个单元格时,公式存储。



我查看了微软的开发中心的信息: p>

Range.Formula Range.Formula Excel 2013的属性(Excel 2003没有此属性的页面)



Range.Value Excel 2003的属性(展开Value属性适用于Range对象)标题



我也搜索为什么使用Range.Formula而不是Range.Value VBA Excel,找不到与我的问题相关的任何内容。



Range.Value 。

>

其他人说使用 Range.Formula on st ack overflow(对不起,我失去了对确切问题的引用...)

解决方案

在数据值方面: p>

想象一下,您可以使用整数,对某些计算进行加倍,如果您使用.formula,您将会受到影响。因为 .FORMULA 总是返回一个String。 (任何设置为.formula的值都不是一个普通值而不是一个公式)除非你有异常处理和你的代码中的extras可用。而 .VALUE 根据您的预期,返回您的数据的数据类型。



在检索公式方面:
值是设置公式但不能检索的一种方式。



所以,您看到这些方法是为了原因引入的,并帮助您使用所需的正确属性。 :-)


I was wondering why in VBA code for Excel 2003 do we even need to use Range.Formula to write a formula to a cell instead of just using Range.Cell? They both write Strings to the cell that become forumlas, and the formula works (from what I've tested).

ActiveCell.Value="=If(True,""yes"",""no"")"

and

ActiveCell.Formula="=If(True,""yes"",""no"")"

do the same thing for me (when I select a cell and execute each of the above code segments separately in separate cells). They both show the "yes" value in the cell and the formula is stored when I click to view each cell.

I looked on Microsoft's Dev Center for info:

Range.Formula Range.Formula Property for Excel 2013 (Excel 2003 did not have a page for this Property)

Range.Value Property for Excel 2003 (Expand the "Value property as it applies to the Range object." heading

I also googled "Why use Range.Formula instead of Range.Value VBA Excel" and couldn't find anything that related to my question.

Some people said, use Range.Value.

Some others say use Range.Formula on stack overflow (Sorry I lost the reference to the exact question...)

解决方案

In terms of values of data:

Imagine you have integers, doubles for certain calculations and if you use .formula you gonna get screwed. Because .FORMULA always return a String. (Any value set to .formula without is a plain value not a formula) Unless you have exception handling and the extras ready in your code. Whereas .VALUE returns your data's data type as you expect them to be.

In terms of retrieving formula: Value is one way road in case to set formula but not to retrieve.

So you see these methods are introduced for a reason and help you to work with right properties you require. :-)

这篇关于为什么使用Range.Formula在VBA for Excel 2003而不是Range.Value?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆