+ Reply to Thread
Results 1 to 10 of 10

Edit chart seriescollection within a "With" - "End With" Block

Hybrid View

gipsyfkls14 Edit chart seriescollection... 10-24-2018, 06:36 PM
AlphaFrog Re: Edit chart... 10-24-2018, 07:08 PM
gipsyfkls14 Re: Edit chart... 10-24-2018, 08:11 PM
AlphaFrog Re: Edit chart... 10-24-2018, 08:41 PM
gipsyfkls14 Re: Edit chart... 10-24-2018, 11:55 PM
AlphaFrog Re: Edit chart... 10-25-2018, 07:10 AM
gipsyfkls14 Re: Edit chart... 10-25-2018, 07:52 AM
gipsyfkls14 Re: Edit chart... 10-25-2018, 11:14 AM
AlphaFrog Re: Edit chart... 10-27-2018, 07:28 AM
gipsyfkls14 Re: Edit chart... 10-29-2018, 09:18 PM
  1. #1
    Forum Contributor
    Join Date
    04-22-2014
    Location
    Turrialba, Costa Rica
    MS-Off Ver
    Excel 2010
    Posts
    108

    Edit chart seriescollection within a "With" - "End With" Block

    Hello.
    In Excel Worksheet I need to edit a Chart (seriescollection values and format.fill
    I got a code with the macro recorder on. For me such codes are confusing.
    I need to modify the following codes to look for efficiency.

    Here my codes:

    Sub editseriescollection()
    	ActiveSheet.ChartObjects("Gráfico 1").Activate
    	ActiveChart.FullSeriesCollection(2).Values = "=qry_123!$C$2:$C$15"
    	ActiveSheet.ChartObjects("Gráfico 1").Activate
    	ActiveChart.Axes(xlCategory).Select
    	ActiveChart.FullSeriesCollection(1).XValues = "=qry_123!$E$2:$E$15"
    	ActiveChart.ChartArea.Select
    End Sub
    Sub editformarfill()
        ActiveChart.FullSeriesCollection(1).Select
        Selection.Format.Fill.Visible = msoFalse
        ActiveChart.ChartArea.Select
    End Sub
    How can I write these codes lines within a "With" "End With Code?
    Also, how can I write
    =qry_123!$C$2:$C$15
    As VBA:
    qry_123 Range("C2", Range("C2").End(xlDown))
    If this is correct.

    I hope some else can help me.
    Cheers

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Edit chart seriescollection within a "With" - "End With" Block

    Not tested...

    Sub editseriescollection()
        With ActiveSheet.ChartObjects("Gráfico 1").Chart
            .FullSeriesCollection(2).Values = "=qry_123!C2:C" & Range("qry_123!C2").End(xlDown).Row
            .FullSeriesCollection(1).XValues = "=qry_123!E2:E" & Range("qry_123!E2").End(xlDown).Row
        End With
    End Sub
    
    Sub editformarfill()
        ActiveChart.FullSeriesCollection(1).Format.Fill.Visible = msoFalse
    End Sub
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    04-22-2014
    Location
    Turrialba, Costa Rica
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Edit chart seriescollection within a "With" - "End With" Block

    I really appreciate your reply.

    I wrote the first code as:
    Sub editseriescollection()
        With ActiveSheet.ChartObjects("Gráfico 1").Chart
            .FullCollection(2).Values = Range("A2", Range("A2").End(xlDown))
            .FullCollection(1).XValues = Range("E2", Range("E2").End(xlDown))
        End With
    End Sub
    VBA displays 'Error 438 Object does not support this property or method' here:
    .FullCollection(2).Values = Range("A2", Range("A2").End(xlDown))
    Sub editformarfill()
    
    With second code:
    Set ch = ActiveChart.FullSeriesCollection(1) .Format.Fill.Visible = msoFalse
    End Sub
    VBA displays 'Error 438 Object does not support this property or method' here:
    Set ch = ActiveChart.FullSeriesCollection(1) .Format.Fill.Visible = msoFalse
    I am trying to write codes inside a With End With Block.
    Moreover, I tried to declare variables such as.
    Dim ws As Excel.Worksheet, xlChart As Excel.ChartObject
    Set ws = wb.Sheets("qry_123")
    Set xlChart = ws.ChartObjects(1)
    I spent hour and hours googling and I did not find similar code examples.

    Any help is really welcome

    Cheers

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Edit chart seriescollection within a "With" - "End With" Block

    Did you try the code I posted without change? If yes, did it work?

    Why are you changing the editformarfill code I suggested?

  5. #5
    Forum Contributor
    Join Date
    04-22-2014
    Location
    Turrialba, Costa Rica
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Edit chart seriescollection within a "With" - "End With" Block

    Hello.
    Yes, I tested your code. Works well.
    I really apologize. First, I just to write my messages in NotePad. I think my previous post was a problem of copy and paste.

    Only the second code displays "Runtime Error 91: Object variable or with block variable not set"
     ActiveChart.FullSeriesCollection(1).Format.Fill.Visible = msoFalse
    I have been trying to fix it, but error still ocurred.

    Cheers

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Edit chart seriescollection within a "With" - "End With" Block

    Did you first select the chart before running the editformarfill macro?

  7. #7
    Forum Contributor
    Join Date
    04-22-2014
    Location
    Turrialba, Costa Rica
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Edit chart seriescollection within a "With" - "End With" Block

    Hello. Thanks

    To test both codes I used F8.
    First I ran the first code that works perfectly.
    Then, I ran the second code and "Runtime Error 91: Object variable or with block variable not set"

    Cheers

  8. #8
    Forum Contributor
    Join Date
    04-22-2014
    Location
    Turrialba, Costa Rica
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Edit chart seriescollection within a "With" - "End With" Block

    AlphaFrog

    I did a few changes to your codes and now all three are working well:

    First code:
    Sub editseriescollection()
        'Set series collection values in chart
    With ActiveSheet.ChartObjects("Gráfico 1").Chart
            .FullSeriesCollection(2).Values = "=qry_123!C2:C" & Range("qry_123!C2").End(xlDown).Row
            .FullSeriesCollection(1).XValues = "=qry_123!E2:E" & Range("qry_123!E2").End(xlDown).Row
        End With 'En set series collection values in chart
    End Sub
    Second code
    Sub sc1_invisible(1)
    	'turn seriescollectio1 invisible
        With ActiveSheet.ChartObjects("Gráfico 1").Activate
            With ActiveChart.FullSeriesCollection(1)
                .Format.Fill.Visible = msoFalse
            End With
        End With ' end seriescollection(1) invisible
    End Sub
    Third code
    Sub addcolour_sc2()
    	'add blue colour to seriescolletion(2)
        With ActiveChart.FullSeriesCollection(2).Select
            With Selection.Format.Fill
             .Visible = msoTrue
                .ForeColor.RGB = RGB(0, 112, 192)
                .Transparency = 0
                .Solid
            End With
        End With 'end to add blue colour to seriescolletion(2)
        
    End Sub
    Can you tell if there is a way to simplify the three codes into one code?
    Is possible to simplify the codes using variables? If true, How can I add variables?
    Is it true that from 2010 "fullseriescolletion" should be written as "seriecolletion"?

    I really appreciate your help

    Cheers

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,651

    Re: Edit chart seriescollection within a "With" - "End With" Block

    Don't need variables in his case.

    FullSeriescollection was introduced in 2013. It's is slightly different (having to do with filtered data) than the usual .SeriesCollection but probably is irrelevant in this case. Use Seriescollection for backward compatibility.

    Sub editseriescollection()
        With ActiveSheet.ChartObjects("Gráfico 1").Chart
            .SeriesCollection(2).Values = "=qry_123!C2:C" & Range("qry_123!C2").End(xlDown).Row
            With .SeriesCollection(2).Format.Fill
                .Visible = msoTrue
                .ForeColor.RGB = RGB(0, 112, 192)
                .Transparency = 0
                .Solid
            End With
            .SeriesCollection(1).XValues = "=qry_123!E2:E" & Range("qry_123!E2").End(xlDown).Row
            .SeriesCollection(1).Format.Fill.Visible = msoFalse
        End With
    End Sub

  10. #10
    Forum Contributor
    Join Date
    04-22-2014
    Location
    Turrialba, Costa Rica
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Edit chart seriescollection within a "With" - "End With" Block

    AplphaFrog.
    Your codes work fine.
    I still don't know the use of Exclamation Mark (!) in the code.
    Thank you for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 02-05-2019, 12:03 AM
  2. Replies: 2
    Last Post: 07-24-2017, 02:19 AM
  3. [SOLVED] Column X-Ref list - Sheet1 Col A "pages", Col B:FL "Req" to Sheet2 ColA "req", ColB "page"
    By excel-card-pulled in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 04-07-2017, 09:30 AM
  4. Chart SeriesCollection(i).XValues "error 1004: invalid parameter"
    By aochan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2016, 04:16 AM
  5. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  6. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  7. Error msgs: "Object varible or with block variable not set"; "subscript out of range"
    By menyanthe in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-26-2009, 04:58 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1