Excel-宏基于选择创建图表 [英] Excel - Macro to create chart based on selection

查看:262
本文介绍了Excel-宏基于选择创建图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想就以下问题寻求您的帮助:
因为我必须创建大量图表,所以我想有一个宏,该宏将根据我的选择插入图表。
因为我对VBA没有任何了解,但是现在需要它(至少就目前而言-我真的应该学会自己使用它),感谢您的帮助。
基本上,我需要知道如何调整记录的代码,以便根据我的选择插入图表:

I would like to ask for your help concerning the following issue: For I have to create a large numbers of charts, I would like to have a macro which would insert the chart based on my selection. As I do not have any clue about VBA but need it now (as for now, at least - I really should learn to use it on my own), I would appreciate your help. Basically, I need to know how to adjust the code I recorded, such that the chart will be inserted based on my selection:

Sub chartmacro()
    ActiveCell.Range("A1:E2").Select
    ActiveSheet.Shapes.AddChart2(240, xlXYScatter).Select
    ActiveChart.SetSourceData Source:=Range("Tabelle1!$A$1:$E$2")
End Sub

I不知道如何更改范围语句中的值,以便它们引用我的选择。

I do not know, how to change the values in the "Range"-statement, such that they refer to my selection.

如果您能考虑我的情况,我会很高兴问题。

I would be glad, if you could consider my question.

您真诚的
纪念日

Yours sincerely, Sinistrum

推荐答案

这就是我能为您做的。您可以从这里继续。

This is what I can do for you. You can go further from here.

Option Explicit

Sub Charter()

    Dim my_range    As Range

    Set my_range = Selection
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=my_range

    Cells(1, 1).Select

End Sub

下一步-将图表声明为变量,删除选择项,等等。但是代码正常。

Next steps - declare the chart as variable, remove the selections, etc. But the code works ok.

这篇关于Excel-宏基于选择创建图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆