0

My idea is to use Userform to create graphs in excel. The userform would have two drop down lists: one is for y-axis and the other one is for x-axis. I want the userform to create a graph with chosen y and x axises in excel.

So far, I know how to make userform with drop down list. I need help to get started to do the rest. I don't know what to do next. Please a link to a tutorial of this similar project or ideas of how to do this would be a great help!

4

2 回答 2

1

如果我有你的问题,我不试试这个教程,
图表

是来自一个非常好的网站的一个非常好的教程,我推荐用于图表和一般 Excel。
如果这不是您要找的,请告诉我!
祝你好运 !

于 2013-11-01T18:05:16.387 回答
1

这是如何开始的简短指南。

为图表准备数据

首先,我建议将名称(定义名称)分配给包含数据的范围,并使用与分配给范围的名称完全相同的名称创建数据验证。(在下面的代码中,用户在 A1 中选择 x,在 A2 中选择 y,选择列表可以是:身高、体重、年龄)。

创建一个空的散点图

Sub CreateXYchart()
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlXYScatter
    ActiveChart.SeriesCollection.NewSeries
End Sub

使用宏更新 X 和 Y 值

Sub ChangeXY()

    vXCell = "A1"           ' Where the user chooses x
    vYCell = "B1"           ' Where the user chooses y
    vChartName = "Chart 1"  ' Chart name of XY Scatterplot

    vRangeNameForX = ActiveSheet.Range(vXCell).Value
    vRangeNameForY = ActiveSheet.Range(vYCell).Value

    ActiveSheet.ChartObjects(vChartName).Activate
    ActiveChart.SeriesCollection(1).XValues = Range(vRangeNameForX)
    ActiveChart.SeriesCollection(1).Values = Range(vRangeNameForY)

End Sub

您可以创建一个按钮来运行宏。所以这是开始(代码假设所有内容都在同一张纸上,顺便说一句)。玩得开心。

于 2013-11-01T21:09:54.617 回答