473,395 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

1004 Unable to set the Values property of the Series class

48
Hello,

I've been coding in Access VBA to create an Excel Graph and it was good.

Until I got this error:
1004 Unable to set the Values property of the Series class
Please check the code below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub TestGraph3()
  2.  
  3.     Dim oXL As Excel.Application    ' Excel application
  4.     Dim oBook As Excel.Workbook     ' Excel workbook
  5.     Dim oSheet As Excel.Worksheet   ' Excel Worksheet
  6.     Dim oChart As Excel.Chart       ' Excel Chart
  7.  
  8.     Dim myRange As String
  9.     Dim xlSourceRange As Excel.Range
  10.  
  11.     Dim iRow As Integer      ' Index variable for the current Row
  12.     Dim iCol As Integer      ' Index variable for the current Row
  13.  
  14.     Const cNumCols = 4       ' Number of points in each Series
  15.     Const cNumRows = 5       ' Number of Series
  16.  
  17.     ReDim aTemp(1 To (cNumRows + 1), 1 To cNumCols)
  18.  
  19.     ' Start Excel and create a new workbook
  20.     Set oXL = CreateObject("Excel.application")
  21.     Set oBook = oXL.Workbooks.Add
  22.  
  23.     Set oSheet = oBook.Worksheets.Item(1)
  24.  
  25.     ' Insert data into Cells for the two Series:
  26.     For iCol = 1 To cNumCols
  27.        aTemp(1, iCol) = "A" & iCol
  28.        aTemp(2, iCol) = 1
  29.        aTemp(3, iCol) = 1 + 2
  30.        aTemp(4, iCol) = iCol
  31.  
  32.        If (iCol * 2) <= cNumCols Then
  33.         aTemp(5, iCol) = iCol * 2
  34.        Else
  35.         aTemp(5, iCol) = cNumCols
  36.        End If
  37.     Next iCol
  38.  
  39.     oSheet.Range("A1").Resize(5, cNumCols).Value = aTemp
  40.  
  41.     oSheet.Name = "MyChart_MD"
  42.  
  43.     myRange = "A1:D" & (cNumRows)
  44.     Set xlSourceRange = oBook.Worksheets(1).Range(myRange)
  45.  
  46.     Set oChart = oXL.Charts.Add
  47.  
  48.     With oChart
  49.         .SetSourceData Source:=xlSourceRange, PlotBy:=xlColumns
  50.         .ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column"
  51.  
  52.         .SeriesCollection(1).XValues = oSheet.Range("A1").Resize(1, cNumCols)
  53.         .SeriesCollection(1).Values = oSheet.Range("A2").Resize(1, cNumCols)
  54.         .SeriesCollection(1).Name = "Plan"
  55.         .SeriesCollection(2).Values = oSheet.Range("A3").Resize(1, cNumCols)
  56.         .SeriesCollection(2).Name = "Actual"
  57.         .SeriesCollection(3).Values = oSheet.Range("A4").Resize(1, cNumCols)
  58.         .SeriesCollection(3).Name = "Accu. Plan"
  59.         .SeriesCollection(4).Values = oSheet.Range("A5").Resize(1, cNumCols)
  60.         .SeriesCollection(4).Name = "Accu. Actual"
  61.         .Location Where:=xlLocationAsNewSheet, Name:="chartMD"
  62.  
  63.         .HasTitle = True
  64.         .ChartTitle.Characters.Text = "Chart : MD"
  65.         .Axes(xlCategory, xlPrimary).HasTitle = False
  66.         .Axes(xlValue, xlPrimary).HasTitle = True
  67.         .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Accu."
  68.         .Axes(xlCategory, xlSecondary).HasTitle = False
  69.         .Axes(xlValue, xlSecondary).HasTitle = False
  70.  
  71.         .HasLegend = False
  72.         .HasDataTable = True
  73.         .DataTable.ShowLegendKey = True
  74.     End With
  75.  
  76.     ' Make Excel Visible:
  77.     oXL.Visible = True
  78.     oXL.UserControl = True
  79.     ' Unselect the ActiveChart
  80.     oChart.Deselect
  81.     oXL.ActiveWindow.Zoom = 85
  82.  
  83.     ' Protect whole Worksheet
  84.     oSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
  85.  
  86.     ' Clean-up
  87.     Set oXL = Nothing: Set oChart = Nothing: Set oSheet = Nothing: Set oBook = Nothing
  88.  
  89. End Sub
  90.  
If cNumCols = 3, ERROR occurs in this line:
Expand|Select|Wrap|Line Numbers
  1.         .SeriesCollection(4).Values = oSheet.Range("A5").Resize(1, cNumCols)
  2.  
If cNumCols = 2, ERROR occurs in this line:
Expand|Select|Wrap|Line Numbers
  1.         .SeriesCollection(3).Values = oSheet.Range("A5").Resize(1, cNumCols)
  2.  

cNumCols is supposed to be the number of points in each series.
Not the number of series.
cNumRows is the number of series.

In a situation where there are 4 Series (Actual, Plan, Accu. Actual, Accu. Plan)
how can I display a graph/chart with 3 columns only?

Help will be greatly appreciated.
Sep 11 '08 #1
4 5857
NeoPa
32,556 Expert Mod 16PB
I can't help with this I'm afraid, but I have a couple of suggestions as to how you can make your question more attractive to potential responders.
  1. When you have a large amount of code to post, please do the legwork first to remove anything which is not relevant to the problem. Produce the smallest set of code that you can which still exhibits the problems you're suffering from.
    Simply dumping your native code in for someone else to go through won't win you many friends.
  2. The [ CODE ] tags you've used add line numbers when they display. When referring to lines in your code it is most easy to do this by the line number.
I would just add that, while point number one is about courtesy, it also has the added benefit of giving you a better understanding of your own code as you process through deciding what to strip. In fact it's fairly common during this process to discover for yourself the problem you're posting to find.

Good luck anyway with your question.
Sep 11 '08 #2
keirnus
48
I can't help with this I'm afraid, but I have a couple of suggestions as to how you can make your question more attractive to potential responders.
  1. When you have a large amount of code to post, please do the legwork first to remove anything which is not relevant to the problem. Produce the smallest set of code that you can which still exhibits the problems you're suffering from.
    Simply dumping your native code in for someone else to go through won't win you many friends.
  2. The [ CODE ] tags you've used add line numbers when they display. When referring to lines in your code it is most easy to do this by the line number.
I would just add that, while point number one is about courtesy, it also has the added benefit of giving you a better understanding of your own code as you process through deciding what to strip. In fact it's fairly common during this process to discover for yourself the problem you're posting to find.

Good luck anyway with your question.
Thank you NeoPa for the advice.

I posted them all so others could easily test.
I understand it is not their job to test but to give advice.
I will keep that in mind.


...and I'm still stuck in this weirdness of this Chart's Series Class.
Sep 12 '08 #3
keirnus
48
Finally solved the intermittent problem!

Acknowledgment goes to Mr. Jon Peltier.
He's very helpful and yet an expert in this field.


Line and XY charts don't like it when a series starts with no data.
He's advice is to set Chart Type to xlColumnClustered which will
set blank data into valid ones. Then, re-insert the original line
after setting all the data.

Let's base from the above code.

The following lines must be changed from this:

Expand|Select|Wrap|Line Numbers
  1.         ....
  2.         .SetSourceData Source:=xlSourceRange, PlotBy:=xlColumns
  3.         .ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column"
  4.         ....
  5.  
...into this:
Expand|Select|Wrap|Line Numbers
  1.         ....
  2.         .ChartType = xlColumnClustered
  3.         .SetSourceData Source:=xlSourceRange
  4.         ....
  5.  
Not only the Chart Type and the sequence of the lines have changed
but the SetSourceData as well.

Note:
Not changing the sequence of lines seems not to fix the problem.
It only takes longer time before the error occurs again.
Don't have explanation on this yet.

Now, after modifying as stated above, let's re-insert the original line:
Expand|Select|Wrap|Line Numbers
  1.         ....
  2.         .SeriesCollection(4).Name = "Accu. Actual"
  3.         .ApplyCustomType ChartType:=xlBuiltIn, TypeName:="Line - Column" ' <-- this one!
  4.         .Location Where:=xlLocationAsNewSheet, Name:="chartMD"
  5.         ....
  6.  
Eureka!

Intermittent problem gone.

Hope this helps you the way it helped much to me!


keirnus
Sep 12 '08 #4
NeoPa
32,556 Expert Mod 16PB
Thank you for the answer Keirnus. That's much appreciated.

My earler point, about stripping down the code, was about setting up a test rig rather than simply cutting out what you post from your code. To be honest, although we'd appreciate that method, we very rarely come across it, so don't worry too much (although I would still maintain it often proves a very real benefit to the poster).

Anyway, your posted solution (so clearly explained too) should prove very helpful, so full marks for that :)
Sep 12 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Arun Nair | last post by:
Hi, I have the following jsp page. I am able to view only a part of it(until the occurence of the first City text box). If i remove the first few fields from the page, I am able to see a few...
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
5
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via...
4
by: Chris Bower | last post by:
Reposted from aspnet.buildingcontrols: Ok, I've got a bunch of derived controls that all have a property Rights of type Rights (Rights is an Enumerator). I wrote a custom TypeConverter so that I...
1
by: epatrick | last post by:
I have a series of custom controls developed under ASP.NET 1.1, and I've successfully migrated to ASP.NET 2.0. I have also developed a custom class dervied from System.Web.UI.Page, called...
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
0
by: forgedascendant | last post by:
Good day everyone, I am new to this site so please forgive me if this post isn't completly correct. For the past 2 weeks I have been beating my head against the wall trying to figure out what is...
14
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and...
2
by: Andy B | last post by:
I have the following listView control on a page: <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="PlaceHolder1"> <ItemTemplate> <dl> <dt>
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.