

You can set this number to whatever you want so that the chart fits into your data nicely.Ĩ0 is the position from the top of the worksheet. Change Chart Size and Position Sub CreateChart()ĬhartObjects.Add(10, 80, 300, 175) the numbers here control the size and position of the chart.ġ0 is the position from the left side of the worksheet. Sometimes legends appear by default use False when you want to ensure that none will appear. If you want to make sure there is no legend, set this value to False. HasLegend:=True when this is set to True, a legend will appear - also, often times a legend will appear by default. Put whatever you want within the quotation marks. ValueTitle:="Value Title" the title that goes along the left side of the chart. Set Category and Value Titles Sub CreateChart()ĬategoryTitle:="Category Title", _ ValueTitle:="Value Title", _ĬategoryTitle:="Category Title" the title that goes along the bottom of the chart. Title:="Chart Title" put whatever you want inside of the quotation marks for the title of the chart. Scatter with Smoothed Lines and No Data Markers.
#HOW TO PLOT A GRAPH IN EXCEL USING MACRO FULL#
xlLine is the type of chart that will be used - you can view a full list of possible chart types below here. Gallery:=xlLine the name of this argument is Gallery, which can seem confusing, but it just controls the type of chart that will be used to display your source data. Possible ValuesĪny range from any worksheet, including named ranges. Make sure to specify from which worksheet you want to get the source data, otherwise, it will come from the currently active or visible worksheet. Worksheets("Sheet1").Range("A1:E4") is the range reference.

Source:=Worksheets("Sheet1").Range("A1:E4") this holds the range reference for the chart.
#HOW TO PLOT A GRAPH IN EXCEL USING MACRO HOW TO#
Each section of code in the macro has a comment that explains what that section does, also, each section below here explains how to change and use the macro in more detail. This is the basic code for adding a chart to a worksheet using a macro. 'Create a chart and put the newly created chart inside of the variable created above. 'Tell the macro to make a variable that can hold the chart. Notes Add a Chart with VBA/Macros Sub CreateChart() This tutorial covers what to do when adding the chart. How to add, edit, and position charts in Excel using VBA.
