Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

create line charts with non-contiguous ranges using VBA

Posted on 2014-10-24
4
Medium Priority
?
331 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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

972 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