Excel - Macro to create chart based on selection

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 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.


  • Avoiding the use of Activate and Select when working with charts (Excel)
  • Identify Active Chart and Selected Chart Element in Office-JS
  • VBA chart position changes when rows inserted
  • Running a single macro on several Cells
  • changing axis labels in excel 2007 charts using python win32com
  • Select alternate points and move labels above/below
  • VBA - syntax for .pictures.insert incorrect? Insert method of picture class failed
  • Impala - Get for multiple tables in database concentenated columns
  • IE & Ajax / XPath
  • Ajax or JavaScript: Changing Style According to Server Response
  • Excel - Macro to create chart based on selection
  • Parse blocks in curly brackets
  • unknown value when select from firebird in Node.js
  • WPF View ListView Backwards
  • Produce a matrix using INDEX and MATCH functions
  • How to vectorize a for loop in R
  • Creating an array variable with a variable number of elements
  • Aggregating based on “near” row values
  • Is it possible to add a text overlay to videos?
  • How to copy a Shape to another worksheet (not as a picture)?
  • WPF UI on multiple threads?
  • Custom variables on product details page in Magento
  • Original method still getting called in Moq even after CallBase = true/false
  • Tips for creating scalable WPF user control
  • How to calculate total Fridays between two dates in excel on weekly, biweekly and monthly basis?
  • Tracking screen recorder in windows app
  • Linux command line : edit hacked index files
  • Excel distinct count with conditions
  • A new chart every sheet
  • several dataProvider per one Test in TestNG
  • Updating both a ConcurrentHashMap and an AtomicInteger safely
  • Excel's Macro-Recorder usage
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • How to handle AllServersUnavailable Exception
  • VBA Convert delimiter text file to Excel
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • Reading document lines to the user (python)
  • java string with new operator and a literal