Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

create line charts with non-contiguous ranges using VBA

Posted on 2014-10-24
4
Medium Priority
?
300 Views
Last Modified: 2014-10-26
Dear Experts:

I tried to create a line chart with two data series (two lines) using VBA:

Sub CreateLineChart_non_contiguous_range()
ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=Range( _
        "Tabelle1!$A$5:$E$5;Tabelle1!$A$7:$E$7")
End Sub

Open in new window


The code should produce this chart, but it throws an 1004 error message on 'SetSourceData'

line chart
How is the macro to be re-written on the setSourceData line for it to work.

Help is much appreciated. Thank you very much in advance.

I have attached my sample file for your convenience.


Regards, Andreas
Create-line-chart-non-contiguous-ranges.
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 40402262
A small change required:

Sub CreateLineChart_non_contiguous_range()
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlLine
    ActiveChart.SetSourceData Source:=Sheets("Tabelle1").Range("A5:E5,A7:E7")
End Sub

Open in new window

0
 

Author Closing Comment

by:AndreasHermle
ID: 40402279
Rory, great this did the trick. Thank you very much for your swift and professional help.

Regards, andreas
0
 
LVL 1

Expert Comment

by:Jon_Peltier
ID: 40404090
Probably the semicolon in the SetSourceData statement was the problem. VBA uses commas regardless of the regionalization of Excel.
0
 

Author Comment

by:AndreasHermle
ID: 40404908
Hi jon,  

indeed you are right. Thank you very much for bringing this to my attention. I really appreciate this.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question