And what is the address of the range containing the 10 or 3 or whatever number of rows? What is the cell address of the cell above "COCA COLA"?
I'll assume the range begins in cell D2, as shown below.
The active cell is D7, which has the number of rows to show.
We'll create a couple dynamic Names that the chart will use.
Go to Formulas tab > Define Name. For Name, enter "xCategories", keep Workbook as Scope, and for Refers To enter this formula and click OK:
Code:
=OFFSET(Sheet1!$D$2,1,0,Sheet1!$B$7,1)
This means from our home cell D2, or range is one cell down and zero cells to the right (i.e., D3), and it is B7 rows tall and 1 column wide. So if D7 is 10, it's the range D3:D12. If D7 is 3, it's the range D3:D5.
Return to Formulas tab > Define Name. For Name, enter "yValues", keep Workbook as Scope, and for Refers To enter this formula and click OK:
That means from our reference range xCategories, which we've just defined, use the range zero rows down and one column right. So it has the same number of rows as xCategories.
Make your chart with the range D2:E12 (I made a bar chart, first chart below). Click on the series, and notice the formula in the Formula Bar:
Code:
=SERIES(Sheet1!$E$2,Sheet1!$D$3:$D$12,Sheet1!$E$3:$E$12,1)
Edit this right in the Formula bar, so it looks like this:
Code:
=SERIES(Sheet1!$E$2,Sheet1!xCategories,Sheet1!yValues,1)
Excel will adjust it:
Code:
=SERIES(Sheet1!$E$2,'Workbook Name.xlsx'!xCategories,'Workbook Name.xlsx'!yValues,1)
If D7 is 10, it still looks like the top chart. If D7 is 3, it looks like the bottom chart.
I have several similar examples on my web site:
Dynamic Charts
Dynamic Chart Review
Dynamic Chart with Multiple Series
Dynamic Charts in Excel 2016 for Mac