【问题标题】:How do I have the contents of a cell appear into the message of a msgbox如何让单元格的内容出现在 msgbox 的消息中
【发布时间】:2013-05-27 03:41:43
【问题描述】:

我正在尝试开发一个MsgBox,它在来自单元格引用的MsgBox 中显示一个问题。

所以在下面的消息“请输入公顷数”的示例中,我想从Worksheet1 cell A1 那里接听。

Sub ComplainceQuestion()
    On Error Resume Next
    Dim num As Double
    Dim Save
    num = Application.InputBox(prompt:="Please Enter The Number Of Hectares", Type:=1)
        MsgBox Format(num * 2.47105, "#,##0.00") & " Is the Number Of Acre's."
        Save = MsgBox("Do you want to paste the result in a cell?", vbYesNo)
        If Save = vbYes Then
            Cell = Application.InputBox("Type In The Cell Reference, for example 'G64'")
            Range(Cell).Value = num * 2.471054
        End If
End Sub

【问题讨论】:

    标签: excel cell msgbox vba


    【解决方案1】:

    在您的原始代码中,num 被分配了用户输入的值。要为其分配单元格的值,例如 A1,只需将行 num = Application.Inputbox... 更改为 num = Range("A1").value。修改代码:

    Sub ComplainceQuestion()
    On Error Resume Next
    Dim num As Double
    Dim Save
        num = Range("A1").Value
        MsgBox Format(num * 2.47105, "#,##0.00") & " Is the Number Of Acre's."
        Save = MsgBox("Do you want to paste the result in a cell?", vbYesNo)
        If Save = vbYes Then
            Cell = Application.InputBox("Type In The Cell Reference, for example 'G64'")
            Range(Cell).Value = num * 2.471054
        End If
        End Sub
    

    编辑:将之前提到的行更改为 num = Application.InputBox(prompt:=Range("A1").Value, Type:=1)

    【讨论】:

    • 我还是要显示输入框,有问题。我希望从单元格中提取输入框消息,而不是计算值。谢谢
    猜你喜欢
    • 1970-01-01
    • 2021-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    相关资源
    最近更新 更多