vba 无法修改单元格的 .Text 属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17909289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 22:27:04  来源:igfitidea点击:

Unable to modify the .Text property of a cell

vbaexcel-vbaruntime-errorexcel

提问by Anil

Sub ex2()
    Sheets("sheet2").Range("a2").Text = "Anil"
End Sub

I want to copy the data Anil into cell a2, but I am getting RUN time error saying:

我想将数据 Anil 复制到单元格 a2 中,但出现运行时错误,提示:

Unable to set the Text property of the Range class.

无法设置 Range 类的 Text 属性。

Can any one advice how to work using TEXT METHOD?

任何人都可以建议如何使用文本方法工作吗?

回答by GSerg

.Textis read only.

.Text是只读的。

To set cell values you use the .Valueproperty.

要设置单元格值,请使用该.Value属性。

回答by sous2817

Use the .Value property and not the .Text:

使用 .Value 属性而不是 .Text:

Sub ex2()
    Sheets("sheet2").Range("a2").Value = "Anil"
End Sub

回答by Samir Seetal

According to the following link, you should be using the Value method...

根据以下链接,您应该使用 Value 方法...

http://msdn.microsoft.com/en-us/library/office/gg192736(v=office.14).aspx

http://msdn.microsoft.com/en-us/library/office/gg192736(v=office.14).aspx

Sub ex2()
    Sheets("sheet1").Range("a2").Value = "Anil"
End Sub