vba 在单元格中显示消息框值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45769481/
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
Displaying Message box values in a cell
提问by Naveen VM
Am new to VBA. So posting this question:
我是 VBA 的新手。所以发布这个问题:
Requirement:I want to display my message box values in a cell.
要求:我想在单元格中显示我的消息框值。
Below is my code:
下面是我的代码:
Sub Button1_Click()
MsgBox "value of a cell is" & Worksheets("Sheet1").Range("A1")
End Sub
When i click on the button it is displaying values for the cell A1 as below
当我单击按钮时,它显示单元格 A1 的值,如下所示
But i want the values from the message box to display on any cell.
但我希望消息框中的值显示在任何单元格上。
Lets say i want "value of a cell is 45" to be displayed on some other cell.
假设我希望在其他单元格上显示“单元格的值为 45”。
Thanks in Advance.
提前致谢。
回答by Mrig
Instead of
代替
MsgBox "value of a cell is" & Worksheets("Sheet1").Range("A1")
use
用
Worksheets("Sheet1").Range("E1") = "value of a cell is " & Worksheets("Sheet1").Range("A1")
Change Cell E1
to your desired cell.
更改Cell E1
为您想要的单元格。
回答by Davesexcel
I have to agree with @Mrig You tell a msgbox what to display just like you tell a cell what to display.
我必须同意@Mrig 你告诉一个 msgbox 显示什么,就像你告诉一个单元格显示什么一样。
Sub Button1_Click()
Dim rng As Range, s As String, x As String
Set rng = Range("A1")
s = "value of a cell is "
x = s & rng.Value
MsgBox x
Range("B3") = x
End Sub