473,473 Members | 2,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Run-time error '1004' Unable to set the XValues property of the series class

4 New Member
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 wrong with the macro I created. The problem I am experiancing is that the range I am trying to put together does not seem to be working for some reason. My entire code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Sub Proto1()
  2. '
  3. ' Proto1 Macro
  4. ' Macro recorded 8/30/2007 by aaron.verellen
  5. '
  6.  
  7. '
  8.     Dim CurrentSheet As String, ChartName As String
  9.     Dim RowCount As Integer, ColumnCount As Integer, FirstColumn As Integer, LastColumn, _
  10.         FirstRow As Integer, LastRow As Integer, Row As Integer, Column As Integer, _
  11.         ProductColumn As Integer, ArrayIndex As Integer, ParameterCount As Integer, _
  12.         ItemCount As Integer, MyIndex As Integer
  13.     Dim UserProductFlag As Boolean, NewProductFlag As Boolean
  14.     Dim Possibilities() As String
  15.     Dim ProductXRange As Range, ProductYRange As Range
  16.  
  17.     'Initalize public/global values
  18.     LockProduct = False
  19.  
  20.     'Identify unique products and place into an array
  21.     ArrayIndex = 1
  22.     ReDim Preserve Possibilities(ArrayIndex) As String
  23.     Possibilities(ArrayIndex - 1) = "All"
  24.  
  25.     For Each wsheet In ThisWorkbook.Worksheets
  26.         'CurrentSheet = wsheet.Name
  27.  
  28.         'verify the sheet is a data sheet
  29.         If wsheet.Name Like "* Raw" Then
  30.  
  31.             'find first and last columns
  32.             ColumnCount = 1
  33.             Do Until Len(Sheets(wsheet.Name).Cells(2, ColumnCount + 1).Value) = 0 And Len(Sheets(wsheet.Name).Cells(2, ColumnCount + 2).Value) = 0
  34.                 If Sheets(wsheet.Name).Cells(2, ColumnCount).Value Like "Product" Then
  35.  
  36.                     'construct vector of possible answers
  37.                     p = 3
  38.                     Do Until Len(Sheets(wsheet.Name).Cells(p, ColumnCount).Value) = 0
  39.                         NewProductFlag = False
  40.                         For Each Item In Possibilities
  41.                             If Item Like Sheets(wsheet.Name).Cells(p, ColumnCount).Value Then
  42.                                 NewProductFlag = True
  43.                             End If
  44.                         Next
  45.  
  46.                         If NewProductFlag = False Then
  47.                             ArrayIndex = ArrayIndex + 1
  48.                             ReDim Preserve Possibilities(ArrayIndex - 1) As String
  49.                             Possibilities(ArrayIndex - 1) = Sheets(wsheet.Name).Cells(p, ColumnCount).Value
  50.                         End If
  51.                         p = p + 1
  52.                     Loop
  53.  
  54.                 End If
  55.                 ColumnCount = ColumnCount + 1
  56.             Loop
  57.         End If
  58.     Next
  59.  
  60.     'Cycle through charts finding coresponding worksheets
  61.     'x = 0
  62.     'p = 0
  63.     'For xxx = 1 To Sheets.Count
  64.     '    If TypeName(Sheets(xxx)) = "Chart" Then
  65.     For Each csheet In ThisWorkbook.Charts
  66.             'ChartName = csheet.Name
  67.  
  68.             'get the name of the worksheet being used
  69.             'For x = 1 To Sheets.Count
  70.             '    If TypeName(Sheets(x)) = "Worksheet" Then
  71.             For Each wsheet In ThisWorkbook.Worksheets
  72.                     'CurrentSheet = wsheet.Name
  73.  
  74.                     'verify the sheet is a data sheet
  75.                     If wsheet.Name Like "* Raw" Then
  76.  
  77.                         'find first and last columns
  78.                         ColumnCount = 1
  79.                         FirstColumn = 0
  80.                         LastColumn = 0
  81.                         Do Until Len(Sheets(wsheet.Name).Cells(2, ColumnCount + 1).Value) = 0 And Len(Sheets(wsheet.Name).Cells(2, ColumnCount + 2).Value) = 0
  82.                             'first column
  83.                             If Sheets(wsheet.Name).Cells(1, ColumnCount).Value Like csheet.Name Then
  84.                                 FirstColumn = ColumnCount
  85.                             'last column
  86.                             ElseIf Len(Sheets(wsheet.Name).Cells(2, ColumnCount + 1).Value) = 0 Then
  87.                                 LastColumn = ColumnCount
  88.                             End If
  89.                             If FirstColumn <> 0 And LastColumn <> 0 Then Exit Do
  90.                             ColumnCount = ColumnCount + 1
  91.                         Loop
  92.  
  93.                         'find last row
  94.                         RowCount = 2
  95.                         'CurrentSheet = Sheets(wsheet.Name).Cells(RowCount, FirstColumn).Value
  96.                         Do Until Len(Sheets(wsheet.Name).Cells(RowCount, FirstColumn).Value) = 0
  97.                             RowCount = RowCount + 1
  98.                         Loop
  99.                         LastRow = RowCount - 1
  100.  
  101.                         'figure out product column
  102.                         ColumnCount = FirstColumn
  103.                         Do
  104.                             ColumnCount = ColumnCount + 1
  105.                         Loop Until Sheets(wsheet.Name).Cells(2, ColumnCount).Value Like "Product"
  106.                         ProductColumn = ColumnCount
  107.  
  108. '////////////////////////////////////////////////////////////////////////////////////////////
  109. 'this is to be added to code to input in the product name
  110. 'mid(instr(1,[product string],"+"),1,len([product string])-instr(1,[product string],"+"))
  111. '////////////////////////////////////////////////////////////////////////////////////////////
  112.  
  113.                         If Not LockProduct Then
  114.                             UserProductFlag = False
  115.                             Do
  116.                                 'get user input
  117.                                 With ProductSelection.ComboBox1
  118.                                     For Each Item In Possibilities
  119.                                         .AddItem Item
  120.                                     Next
  121.                                 End With
  122.                                 ProductSelection.Show
  123.  
  124.                                 'make sure user input is good
  125.                                 For Each Item In Possibilities
  126.                                     If Item Like Criteria Then UserProductFlag = True
  127.                                 Next
  128.                             Loop Until UserProductFlag = True
  129.                         End If
  130.  
  131.                         'graph
  132.                         ParameterCount = 1
  133.                         Do While (ParameterCount <= Sheets(csheet.Name).SeriesCollection.Count)
  134.                             'select proper product ranges to graph
  135.                             ItemCount = 0
  136.                             MyIndex = LastRow
  137.                             Do
  138.                                 If Criteria = "All" Then
  139.                                     If ItemCount = 0 Then
  140.                                         Set ProductXRange = Sheets(wsheet.Name).Cells(MyIndex, 3)
  141.                                         Set ProductYRange = Sheets(wsheet.Name).Cells(MyIndex, ParameterCount + 6)
  142.                                     Else
  143.                                         Set ProductXRange = Union(ProductXRange, Sheets(wsheet.Name).Cells(MyIndex, 3))
  144.                                         Set ProductYRange = Union(ProductYRange, Sheets(wsheet.Name).Cells(MyIndex, ParameterCount + 6))
  145.                                     End If
  146.                                     ItemCount = ItemCount + 1
  147.                                 ElseIf Sheets(wsheet.Name).Cells(MyIndex, ProductColumn).Value = Criteria Then
  148.                                     If ItemCount = 0 Then
  149.                                         Set ProductXRange = Sheets(wsheet.Name).Cells(MyIndex, 3)
  150.                                         Set ProductYRange = Sheets(wsheet.Name).Cells(MyIndex, ParameterCount + 6)
  151.                                     Else
  152.                                         Set ProductXRange = Union(ProductXRange, Sheets(wsheet.Name).Cells(MyIndex, 3))
  153.                                         Set ProductYRange = Union(ProductYRange, Sheets(wsheet.Name).Cells(MyIndex, ParameterCount + 6))
  154.                                     End If
  155.                                     ItemCount = ItemCount + 1
  156.                                 End If
  157.                                 MyIndex = MyIndex - 1
  158.                             Loop Until ItemCount = 35 Or MyIndex = 2
  159.  
  160.                             'convert to a column graph
  161.                             Sheets(csheet.Name).ChartType = xlColumnClustered
  162.                             With Sheets(csheet.Name).SeriesCollection(ParameterCount)
  163.                                 .XValues = ProductXRange
  164.                                 .Values = ProductYRange
  165.                             End With
  166.                             'convert back to a line graph
  167.                             Sheets(csheet.Name).ChartType = xlLineMarkers
  168.                             ParameterCount = ParameterCount + 1
  169.                         Loop
  170.                     End If
  171.                 'End If
  172.             Next
  173.             'Next x
  174.         'End If
  175.     'Next xxx
  176.     Next
  177. End Sub
  178.  
The error strikes toward the end of the code on line 163:
I am not sure but I think the problem has to do with the actual range that I am trying to put in for the XValues. Like it doesn't exist or something. Does anyone know what is wrong?

Ok...the problem through talking with coworkers and experimenting is that I am not using a continuous range. When I manually put in ranges I can utilize non continuous ranges however when using a macro that is not so. Does anyone know of a way to get around this problem?

Thanks,
Aaron
Oct 1 '07 #1
0 2932

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

Similar topics

3
by: leroybt.rm | last post by:
Can someone tell me how to run a script from a interactive shell I type the following: >>>python filename >>>python filename.py >>>run filename >>>run filename.py >>>/run filename >>>/run...
4
by: Ed | last post by:
Hello, I took a course in asp about 2 years ago and I was practicing with IIS 5.0. Then I put it down for a while. Now trying to get back to it. I can't run asp files from subdirectories of...
9
by: shank | last post by:
What is the proper syntax to run this command line in ASP? wzzip.exe File.zip File.txt thanks
19
by: Bryan | last post by:
How can i run a bit of code straight from the IDE? Right now i make a temporary button and put the code behind that, then i run debug mode and click on the button. Is there a way to highlight...
7
by: Lee Crabtree | last post by:
I remember when I was first getting into .NET Forms programming that there was a rather emphatic rule about not constructing a form before calling Application.Run with it. So this: ...
8
by: David Thielen | last post by:
Hi; In our setup program how do I determine if I need to run "aspnet_regiis –i" and if so, is there an API I can calll rather than finding that program on the user's disk and calling it? --...
26
by: Chief | last post by:
Hello i would like to know which syntax do i have to use in order to make a program run other *.exe program and also how to put inputs in it for example i want to to make a program that run...
3
by: traceable1 | last post by:
Is there a way I can set up a SQL script to run when the instance starts up? SQL Server 2005 SP2 thanks!
8
by: Sean DiZazzo | last post by:
Is there something special you have to do to get a wxPython app to run remotely under xwindows? My Tkinter apps always automatically work that way, so I was surprised to even be confronted with...
7
by: mxdevit | last post by:
Task: run application from ASP.NET for example, you have a button on ASP.NET page, when press this button - one application is invoked. the code to run application (for example, notepad) is...
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.