Misbehaving Chart Data Sources

schwiggiddy

New Member
Joined
Sep 5, 2017
Messages
31
This code is doing everything I want it to do, except the output is wrong.

Specifically, when "chartstring" is defined, it is defined by the sheet "Summary" from a range spanning A2 to my desired column--but row 3 instead of 2 as is hardcoded into the definition!

What's going on here?

Code:
    chartstring = "Summary!$A$2:$" & colLetter & "$2,Summary!$A$" & rownum - 4 & ":$" & colLetter & "$" & rownum
    Sheets("Score Chart").Activate
    ActiveChart.PlotArea.Select
    ActiveChart.SetSourceData Source:=Range(chartstring)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Worked fine for me. Here's my entire test procedure:

Code:
Sub PopulateChart()
  Dim chartstring As String
  Dim colLetter As String
  Dim rowNum As Long

  colLetter = "E"
  rowNum = 10

  chartstring = "Summary!$A$2:$" & colLetter & "$2,Summary!$A$" & rowNum - 4 & ":$" & colLetter & "$" & rowNum
  Sheets("Score Chart").Activate
  ActiveChart.PlotArea.Select
  ActiveChart.SetSourceData Source:=Range(chartstring)

End Sub
 
Upvote 0
Thanks for checking. It's really strange. I've inserted another row above my heading row and made the necessary changes to the code. Now it works correctly.

There's another issue, too, unrelated I guess...maybe? You see how in defining chartstring there's a rowNum - 4 expression? This gets the chart to show the last 4 entries in the spreadsheet and represents 4 weeks of data. I'd rather have 5 weeks displayed but when I change 4 to 5, the chart displays 6 series.
 
Upvote 0
When I did my test, the chart drew five lines (taking data from five rows). But rownum to rownum - 4 is five rows.
 
Last edited:
Upvote 0
Yeah, I realized that after I posted. After playing around with it, if I change to rownum-3, I get 4 rows charted. At rownum-4, I also get 4 series. But rownum-5 yields 6 lines on the graph. I've changed how I define variables, shifting different parts of chartstring into and out of other variables and hard-coding. I think I'm just going to have to be OK with either 4 or 6 series being charted.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top