首页 文章

在单元格中显示消息框值

提问于
浏览
0

我是VBA的新手 . 所以发布这个问题:

Requirement: 我想在单元格中显示我的消息框值 .

For example:
enter image description here

以下是我的代码:

Sub Button1_Click()

    MsgBox "value of a cell is" & Worksheets("Sheet1").Range("A1")

End Sub

当我点击按钮时,它显示单元格A1的值,如下所示

enter image description here

但我希望消息框中的值显示在任何单元格上 .

让我们说我希望“细胞的 Value 是45”显示在其他一些细胞上 .

提前致谢 .

2 回答

  • 0

    代替

    MsgBox "value of a cell is" & Worksheets("Sheet1").Range("A1")
    

    使用

    Worksheets("Sheet1").Range("E1") = "value of a cell is " & Worksheets("Sheet1").Range("A1")
    

    Cell E1 更改为您想要的单元格 .

  • 1

    我必须同意@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
    

相关问题