Results 1 to 4 of 4

Thread: Update source of chartData

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    10

    Update source of chartData

    I have 4 charts in a sheet called "Menu" that uses a sheet in the image bellow as source. All of them have the first column as the X axis and each chart uses one of the four other columns as Y axis.

    Their sources are :
    =menu_chart_data!$A$1:$B$17
    =menu_chart_data!$A$1:$A$17;menu_chart_data!$C$1:$C$17
    =menu_chart_data!$A$1:$A$17;menu_chart_data!$D$1:$D$17
    =menu_chart_data!$A$1:$A$17;menu_chart_data!$E$1:$E$17

    But this sheet can increase one row every month with another process so I need their source to be from the first row all the way down to the last row that is not a zero.
    Can I do that with VBA?

    Name:  Capturar.JPG
Views: 298
Size:  72.4 KB

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Update source of chartData

    Can I do that with VBA?
    yes
    you could do a find on the first column to macth the 0, then just set the source to match the range above
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2018
    Posts
    10

    Re: Update source of chartData

    How can I put the formula in the source?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Update source of chartData

    try like
    Code:
    Dim sh As Worksheet, ch As Chart, s As Series
    
    Set s = ch.SeriesCollection(1)
    Set fnd = sh.Range("a:a").Find(0, , , xlWhole)
    addr = fnd.Offset(-fnd.Row + 1).Resize(fnd.Row - 1).Address
    s.Formula = Left(s.Formula, InStr(s.Formula, "!")) & addr & Right(s.Formula, 3)
    where you preset ch to your chart and sh to the sheet containing the data
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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