Results 1 to 4 of 4

Thread: [RESOLVED] removing series from chart

  1. #1

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Resolved [RESOLVED] removing series from chart

    Hey all,

    I'm having one of those crazy problems where code worked for like 5 minutes, then after no changes, stops working.. ugh

    Anyway.. pretty simple. Basically creating a chart, and want to get rid of the initial series that the chart comes with after creation. I have this exact code working in another part of my project, and this code worked fine for a little, then error message saying deletion of series failed.

    vb Code:
    1. Set chartLeach = Charts.Add
    2.     chartLeach.name = chartName
    3.    
    4.     With chartLeach
    5.         If graphStyle = 2 Then
    6.             .ChartType = xlColumnClustered
    7.         ElseIf graphStyle = 1 Then
    8.             .ChartType = xlLine
    9.         End If
    10.        
    11.         Do Until .SeriesCollection.count = 0
    12.             .SeriesCollection(1).Delete 'FAILING
    13.         Loop
    14.     End With

    Is this bad practice? I'm baffled, especially after this exact code works in other spots of my project...

    Thanks much!

  2. #2

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: removing series from chart

    hmm..

    restarted the workbook and now it's working again... strange. I'll mark this as resolved, but if anyone has any comments on better practice it would be much appreciated!

    Thanks

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [RESOLVED] removing series from chart

    is that the complete code?

    if yes, then the code never enters the if or the Do loop

    To Check you can try this

    Code:
    Sub test()
    Set chartLeach = Charts.Add
        chartLeach.Name = chartname
        
        With chartLeach
            If graphStyle = 2 Then
                .ChartType = xlColumnClustered
                MsgBox "Entered the loop" '<===============
            ElseIf graphStyle = 1 Then
                .ChartType = xlLine
                MsgBox "Entered the loop" '<===============
            End If
            
            Do Until .SeriesCollection.Count = 0
                MsgBox "Entered the loop" '<===============
            Loop
        End With
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] removing series from chart

    hmm.. yeah it's not the complete code. the graph style is defined earlier and it enters those ifs...

    but there is something wierd about the .delete loop b/c it is actually entering it at some points and others not. I gotta do some more testing. b/c I changed from unloading that form to merely hiding it, and now I'm not encountering the problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width