473,765 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
+ 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 2948

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

Similar topics

3
4930
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 filename.py
4
3217
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 my root directory, but I can run asp files from the root directory of my website and I can run htm files from the subdirectories. If I run localhost/mytest.asp
9
19734
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
2226
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 some code and tell it to run that? Is there a "scratchpad" type window like in VBA where I can write some simple code to be executed? Thanks for the help in advance
7
2949
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: Application.Run(new Form1()); was okay, but this: Form1 form = new Form1();
8
3018
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? -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
26
2311
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 other file call try.exe and save all the stdout into a file thanx
3
11300
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
2651
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 this problem. ~Sean
7
11746
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 (on C#) System.Diagnostics.Process.Start("notepad");
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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 we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.