在messageBox

时间:2016-02-03 05:19:53

标签: excel vba excel-vba

我在用户表单中显示所选选项时遇到问题。我有两个名为opt750的选项按钮,值为750,另一个为opt1000,值为1000.从选项中选择后,它应显示在msg框中。我试过的代码如下,这是用户点击确定按钮时显示的整条信息:

MsgBox "Date Received : " & vbTab + vbTab + date.Value + vbNewLine & _
"Amount Received : " & vbTab + amount.Value + vbNewLine & _
"Received Type: " & vbTab + vbTab + acnType.Value + vbNewLine & _
vbNewLine & _
"Received the amount of : " 'this is where I should 
'call the result of the selected option button

我喜欢将结果显示在msgbox中:

Date Received : 01/01/2011
Amount Received: 10000
Received Type: ATM
Received the total amount of : 750 'if the button selected is 750 otherwise, 1000

非常感谢!

1 个答案:

答案 0 :(得分:1)

假设您的用户表单中包含以下选项...

enter image description here

单击确定按钮消息框将根据用户选择选项显示在我的下面的代码中。

 Private Sub CommandButton1_Click()
        Dim amt As Integer
        If (opt750) Then
          amt = 750
        ElseIf (opt1000) Then
          amt = 1000
          Else
          amt = 0
        End If
        MsgBox "Received the amount of :" & amt

 End Sub