![]() Whenever adding a chart via VBA it's a good practice to first delete any series which got auto-added. If you insert a chart sheet or chartobject while there's data selected on a worksheet, the chart will auto-plot the selected data. Axes(xlValue, xlPrimary).AxisTitle.Text = "Power (kW)" Excel will plot the first column of the range on the X axis, the second on the Y axis. Second, select JUST ONE cell in the data range and insert a scatter chart. Axes(xlValue, xlPrimary).HasTitle = True First of all, you can always insert a blank scatter plot, then edit the data source and select the ranges for X and Y manually. Axes(xlCategory, xlPrimary).AxisTitle.Text = "Time (h)" Axes(xlCategory, xlPrimary).HasTitle = True SetElement (msoElementChartTitleAboveChart) ' If there is a previous chart, delete it Any ideas on whats causing this? Sub CreatingChartOnChartSheet() Continuing to rerun my code repeats the cycle of good plot -> bad plot -> good plot. Then, when I run the code a third time, I get the correct plot once again. ![]() However, when I rerun the code with a "Power Chart" present, I get 3 additional series showing up, two with blank data and one with only y values, corresponding to the last column in my worksheet. when there is no "Power Chart" present), it plots the data correctly. When I run the code shown below for the first time (i.e. ![]() I am trying to create an xy scatter plot on its own worksheet using VBA.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |