【问题标题】:VBA Chart using a Range as a messagebox使用范围作为消息框的 VBA 图表
【发布时间】:2016-06-27 14:02:37
【问题描述】:

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

我下面的代码要求一个范围,然后它不会创建图表。 任何帮助都会有所帮助

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)
  Exit Sub
 '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 Sub
End Function

【问题讨论】:

    标签: vba charts range messagebox


    【解决方案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 控件可能会为选择范围提供更好的用户体验。它比输入框返回无效范围的可能性更小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2018-12-18
      • 2021-05-12
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      相关资源
      最近更新 更多