473,397 Members | 1,974 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,397 software developers and data experts.

Errors while creating Charts in Excel VBA 2010

I have written below code to generate a Graph based on a data in a sheet. But getting below errors.
1. The specified dimension is not valid for the current chart type.
2. Method 'MarkerStyle' of object 'Series' Failed
3. Method 'Delete' of object 'Series' Failed
4. Application Defined or object Defined Error

Below code creates total 36 Graphs first few graphs creats successfully but after that it fails and throws above mentioned error.
Expand|Select|Wrap|Line Numbers
  1. Sub CreateWeeklyGraph(ByVal rptName As String, ByVal numDays As Integer)
  2. On Error GoTo Handler
  3. Dim a, b, c, d, e, f, comma As Variant
  4. Dim i, j, k, rCount, chartCount As Integer
  5. Dim cto As ChartObject
  6. Dim cht, chtChart As Chart
  7. Dim CurSheet As Worksheet
  8. Dim sheetName As String
  9. i = 2
  10. k = 2
  11. 'Application.ScreenUpdating = False
  12. frmEEMReport.ProgressBar3.Visible = True
  13. frmEEMReport.lblStep2Status.Visible = True
  14. frmEEMReport.ProgressBar3.Min = 63
  15. frmEEMReport.lblStep2Status.Caption = ""
  16. 'Workbooks.Open rptName
  17. While i <= numDays
  18.  
  19.         'Initialise progress bar
  20.         frmEEMReport.ProgressBar3.Max = 100
  21.         frmEEMReport.ProgressBar3.Value = i + 63
  22.         frmEEMReport.ProgressBar3.Refresh
  23.         frmEEMReport.lblStep2Status.Caption = "Graph Creation " & frmEEMReport.ProgressBar3.Value & " % Completed"
  24.         DoEvents
  25.         Application.Workbooks("EEM V1.0").Activate
  26.         sheetName = Range("A" & i).Value
  27.         Application.Workbooks(Dir(rptName)).Activate
  28.         Sheets(sheetName).Activate
  29.  
  30.         rCount = Range("E1", Range("E1").End(xlDown)).Rows.Count
  31.         'HERE CALCULATE AVERAGE VALUE BASED ON TIME
  32.         rCount = rCount + 1
  33.         Range("E" & rCount).Select
  34.         'ActiveCell.FormulaR1C1 = "=AVERAGE(R[-3]C:R[-1]C)/1000"
  35.         ActiveCell.Formula = "=AVERAGE(E2:E" & rCount - 1 & ")/ 1000" '  R[-2]C:R[-1]C)/1000"
  36.         Selection.AutoFill Destination:=Range("E" & rCount & ":AZ" & rCount), Type:=xlFillDefault
  37.         'Range("E" & rCount & ":AZ" & rCount).Select
  38.         Range("D2").Select
  39.         ActiveCell.Formula = "=MAX(C2:C" & rCount - 1 & ")"
  40.  
  41.         Range("YZ2").Select
  42.         ActiveCell.Formula = "=D2"
  43.         Selection.NumberFormat = "0;[Red]0"
  44.         Range("A1").Activate
  45.         'Application.Workbooks(Dir(rptName)).Activate
  46.         d = "='" & sheetName & "'" & "!$E$1:$AZ$1"
  47.         e = "='" & sheetName & "'" & "!$C$"
  48.         a = "'" & sheetName & "'" & "!$A$2"
  49.  
  50.         b = "'" & sheetName & "'" & "!$E$1"
  51.         c = "'" & sheetName & "'" & "!$E$" & rCount & ":" & "$AZ$" & rCount
  52.         Range("A" & k & ",E1,E" & rCount & ":AZ" & rCount).Select
  53.         DoEvents
  54.         Sleep (500)
  55. '        Set CurSheet = Worksheets(sheetName)
  56. '        Set chtChart = CurSheet.ChartObjects.Add(Left:=100, Width:=300, Top:=100, Height:=300).Chart
  57.         ActiveSheet.Shapes.AddChart
  58.         DoEvents
  59.         'Get a reference to the chartobject on the sheet
  60.         Set cto = Sheets(sheetName).ChartObjects(1)
  61.  
  62.         'Get a reference to the chart
  63.         Set cht = cto.Chart
  64.  
  65.         cto.Select
  66.         DoEvents
  67.  
  68.         ActiveChart.ChartType = xlLineStacked
  69.  
  70.         'ActiveChart.SetSourceData Source:=Range("'02 July'!$A$2,'02 July'!$C$1,'02 July'!$C$2:$AX$2")
  71.         ActiveChart.SetSourceData Source:=ActiveSheet.Range("" & a & "," & b & "," & c & "")
  72.         ActiveChart.ApplyLayout (1)
  73.         ActiveChart.PlotArea.Select
  74.         DoEvents
  75.         'Sleep (1)
  76.         ActiveChart.SeriesCollection(1).Delete
  77.         ActiveChart.SeriesCollection(1).Delete
  78.         ActiveChart.SeriesCollection(1).XValues = "" & d & ""
  79.         'ActiveChart.SeriesCollection(1).XValues = "='02 July'!$C$1:$AX$1"
  80.         'ActiveSheet.ChartObjects("Chart " & chartCount).Activate
  81.  
  82.         ActiveSheet.ChartObjects(1).Activate
  83.         DoEvents
  84.         ActiveChart.ChartTitle.Text = sheetName
  85.         ActiveChart.Axes(xlValue).AxisTitle.Select
  86.         ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Response Time (in sec)"
  87.         Selection.Format.TextFrame2.TextRange.Characters.Text = "Response Time (in sec)"
  88.         With Selection.Format.TextFrame2.TextRange.Characters(1, 13).ParagraphFormat
  89.             .TextDirection = msoTextDirectionLeftToRight
  90.             .Alignment = msoAlignCenter
  91.         End With
  92.         With Selection.Format.TextFrame2.TextRange.Characters(1, 13).Font
  93.             .BaselineOffset = 0
  94.             .Bold = msoTrue
  95.             .NameComplexScript = "+mn-cs"
  96.             .NameFarEast = "+mn-ea"
  97.             .Fill.Visible = msoTrue
  98.             .Fill.ForeColor.RGB = RGB(0, 0, 0)
  99.             .Fill.Transparency = 0
  100.             .Fill.Solid
  101.             .Size = 10
  102.             .Italic = msoFalse
  103.             .Kerning = 12
  104.             .Name = "+mn-lt"
  105.             .UnderlineStyle = msoNoUnderline
  106.             .Strike = msoNoStrike
  107.         End With
  108.         ActiveChart.Legend.Select
  109.         'ActiveChart.SeriesCollection(1).Name = "='02 July'!$A$2"
  110.         ActiveChart.SeriesCollection(1).Name = sheetName
  111.  
  112.         'ActiveChart.PlotArea.Select
  113.         ActiveChart.ChartType = xlLineMarkers
  114.         ActiveChart.ChartArea.Select
  115.         DoEvents
  116.         ActiveSheet.Shapes("Chart " & cto.ZOrder).ScaleWidth 1.5961765092, msoFalse, msoScaleFromTopLeft
  117.         ActiveSheet.Shapes("Chart " & cto.ZOrder).ScaleHeight 1.4803109507, msoFalse, msoScaleFromTopLeft
  118.         DoEvents
  119.         Sleep (400)
  120.  
  121.         'Add Threshold Line
  122.         ActiveChart.SeriesCollection.NewSeries
  123.         DoEvents
  124.         Sleep (500)
  125.         ActiveChart.SeriesCollection(2).Name = "=""Threshold Value"""
  126.  
  127.         comma = ","
  128.         f = "='" & sheetName & "'" & "!$YZ$2"
  129.         e = comma & "'" & sheetName & "'" & "!$YZ$2"
  130.         ActiveChart.SeriesCollection(2).Values = "" & f & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & e & ""
  131.  
  132.         '--ActiveSheet.ChartObjects(1).Activate
  133.         ActiveSheet.ChartObjects(1).Select
  134.         ActiveChart.SeriesCollection(2).Select
  135.  
  136.         ActiveChart.Axes(xlCategory).Select
  137.         DoEvents
  138.         Selection.MajorTickMark = xlOutside
  139.         ActiveChart.Axes(xlCategory).TickLabels.Orientation = 90
  140.         ActiveChart.Axes(xlCategory).AxisBetweenCategories = False
  141.  
  142.          With ActiveSheet.Shapes("Chart " & cto.ZOrder).Line
  143.             .Visible = msoTrue
  144.             .ForeColor.ObjectThemeColor = msoThemeColorText1
  145.             .ForeColor.TintAndShade = 0
  146.             .ForeColor.Brightness = 0
  147.             .Transparency = 0
  148.             .Weight = 1.75
  149.         End With
  150.  
  151.     '   Add Text Box to graph to put the comment
  152.     '   ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 40, 340, 580, 50).ShapeStyle = msoLineStylePreset1
  153.         ActiveChart.SeriesCollection(1).Select
  154.         Sleep (400)
  155.         DoEvents
  156.         With Selection
  157.             .MarkerSize = 1.5
  158.             .MarkerStyle = -4142
  159.         End With
  160.  
  161.         ActiveChart.SeriesCollection(2).Select
  162.         Sleep (400)
  163.         DoEvents
  164.         'Sleep (1)
  165.         With Selection
  166.             .MarkerStyle = -4142
  167.             .MarkerSize = 1.5
  168.             .Border.Color = RGB(120, 0, 0)
  169.         End With
  170.         Set cto = Nothing
  171.         Set cht = Nothing
  172.         Set chtChart = Nothing
  173.         i = i + 1
  174. Wend
  175. Application.Workbooks(Dir(rptName)).Activate
  176. 'Application.Workbooks(Dir(rptName)).Save
  177. Exit Sub
  178. Handler:
  179.     MsgBox Err.Description
  180.     Exit Sub
  181.     frmEEMReport.btnExcelReport.Enabled = True
  182. End Sub
  183.  

Any help appreciated.
Thanks in Advance.
Aug 6 '13 #1
0 1536

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

Similar topics

2
by: Thomas Guettler | last post by:
Hi! I need to create some simple charts with python. A list contains integers between 0 and mymax. I want to see how the values are distributed (How many are 0, how many are mymax, ...). The...
6
by: Kerri McDonald | last post by:
We have an application where the user fills out many screens and when they are done, we are supposed to display the text they entered in a word or excel format. That is fairly easily accomplished...
1
by: Al Bahr | last post by:
Hi, Anyone aware of sample codes or article on creating Charts such as line, or Bar in VB.net? Thanks Al
3
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to...
1
by: Mitch | last post by:
I am using Access to create an Excel spreadsheets with graphs related to rows on the sheet1 to the graph on sheet2. I am using the same data but different subsets of the data to make different...
7
by: Paul | last post by:
Hi I have created an excel file download feature within a .net application using Microsoft Office XP primary interop assembly for excel. I was just wondering if anyone knows if you can also embed...
1
by: amarnathreddy | last post by:
#!/usr/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; my $Excel = Win32::OLE->new('Excel.Application', 'Quit'); my $Book =...
0
by: rihara | last post by:
Hi, I want to create charts in Excel and I have different matrices (ranges). Range("K2:P14").Select Charts.Add ActiveChart.ChartType = xlLineMarkers ActiveChart.SetSourceData...
1
by: Catbkr1 | last post by:
I have to automatically create some Excel Spreadsheets based on automatically generated .CSV files that are produced overnight. Each .CSV has several columns that need to be deleted. The same...
0
Pakmarshal
by: Pakmarshal | last post by:
I developed a 64-bit Excel Addin. For testing I added it on a laptop (64-bit machine with 64-Windows7 Enterprise and 64-bit Office 2010) , its works fines i can call n use its functions. but when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.