使用范围作为消息框的VBA图表

时间:2016-06-27 14:02:38

标签: vba charts range messagebox

我正在尝试创建一个图表,但有一个弹出框要求您选择范围,因为这将每月更改。

我在下面的代码询问范围,然后它不会创建图表。 任何帮助都会有所帮助

If UserForm1.rvpCheckbox.Value = False And _
    UserForm1.umCheckbox.Value = False And _
    UserForm1.uwCheckbox.Value = False And _
    UserForm1.baCheckbox.Value = False And _
    UserForm1.uaCheckbox.Value = False And _
    UserForm1.otherCheckbox.Value = False Then
        UserForm1.otherCheckbox.Caption = "Please select an Audience"
        '...or maybe a message box instead?
        MsgBox "Please select an Audience"
        Exit Function
End If

1 个答案:

答案 0 :(得分:1)

尝试删除Exit SubEnd Sub,如下所示:

Sub test()
    'Set up the variables.
    Dim rng As Range

    'Use the InputBox dialog to set the range for MyFunction
    Set rng = Application.InputBox("Range:", Type:=8)

     'Call MyFunction
    ActiveCell.Value = MyFunction(rng)
End Sub

Function MyFunction(rng As Range) As Double

    MyFunction = ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlLineMarkers
    ActiveChart.SetSourceData Source:=rng
End Function

第一个退出子计划阻止test调用MyfunctionEnd Sub在函数中没有earthly business

RefEdit控件可能会为选择范围提供更好的用户体验。它比Inputbox更不可能返回无效范围。