0

我正在尝试开发一个MsgBoxMsgBox在单元格引用

因此,在下面的 Msg“请输入公顷数”的示例中,我想从 say 中接听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
4

1 回答 1

3

在您的原始代码中,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)

于 2013-05-27T04:13:37.417 回答