vba 如何在vba代码中显示单元格中的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10793139/
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
How to display value from cell in vba code?
提问by Saumil Shah
Row_No = 5
Row_No = 5
MsgBox Range.("A & Row_No").value
MsgBox Range.("A & Row_No").value
i have above code but it gives me error 1004
..please help me with this.
我有上面的代码,但它给了我错误1004
..请帮我解决这个问题。
回答by Cylian
Just try this
试试这个
MsgBox Range.("A" & Row_No).Value
or this
或这个
MsgBox Range.("A" & Row_No).Text
or this
或这个
MsgBox Cells(1,"C")
Problem with the code you used is nothing but placing of &
and "
in wrong place.
您使用的代码的问题只是放置&
和"
错误的位置。
Hope this helps.
希望这可以帮助。
回答by Wingman4l7
When doing concatenation, keep in mind that strings will be in quotes and variables will not -- think of the quotes as telling the compiler to interpret what is between them as literal text. A good IDE will usually indicate this via syntax highlighting.
在进行连接时,请记住字符串将包含在引号中,而变量则不会 - 将引号视为告诉编译器将它们之间的内容解释为文字文本。一个好的 IDE 通常会通过语法高亮显示这一点。
So, in your code, the Range()
method is being passed the string A & Row_No
instead of A5
-- so it errors out.
因此,在您的代码中,该Range()
方法正在传递字符串A & Row_No
而不是A5
- 所以它出错了。