I'm trying to make a graph for excel that takes data from a extending plot range, and I'm trying to use define a name with the range and use it as a legend entry, which doesn't work.
Formula for name I used.
=OFFSET(Sheet2!A2, 0, 0, COUNTA (Sheet2!A:A) - 1)
the name + range formula I used
the error
You should always be able to find a way around Offset. It's a volatile function and using Index is almost always better. It looks like you're trying to create a range that's dynamic... so this should work:
(Updated with absolute references)
=Sheet2!$A$2:INDEX(Sheet2!$A:$A,COUNTA(Sheet2!$A:$A),1)
See sample spreadsheet using it in a sum function. You'd have to use that for the named range, but just a copy paste.
Related
I would like to input a number in a range from another sheet and I don't know how to do it.
The function:
=PERCENTRANK.INC(sheet1!$C$6:$C$**96**;sheet1!$C$6))
For example: The result of this function should be in a range of 10 days. So the range would be sheet1!M6:M16 (not sheet1!M6:M96)
I want input different numbers on the "96" space.
And I have a large matrix so it's impossible to do it manually.
Thank you so much!!
Avoid the use of volatile INDIRECT and OFFSET set-ups when a perfectly good non-volatile INDEX set-up is available.
=PERCENTRANK.INC(Sheet1!C6:INDEX(Sheet1!C:C,G3),Sheet1!C6)
=Average(indirect("sheet1!M6:M"&A1)) in A1 put 96
You may want to replace the range inside the average: =AVERAGE(FILTER(…)) where you can define a range by certain criteria.
edit:
If you want to use the absolute cell reference, see the answer from Zorigt.
Alternatively, you could also use the OFFSET function to define your range starting from a reference cell (e.g. 10 rows for 10 days)
With the filter you could define e.g. from which day to which day and/or any other criteria
If you want dynamic range as per the input you will give better make use of the address function with indirect. indirect takes static cell reference.
=ADDRESS($C$3+6,3)
Result: $C$16
=PERCENTRANK.INC($C$6:INDIRECT(ADDRESS($C$3+6,3)),C6)
however this function doesn't ignore the values outside the range that you gave.
so to overcome this problem you can check if the range you gave and the current row/cell in the formula is greated then or equal.
=IF(ROW(INDIRECT($D$3))>=ROW(),PERCENTRANK.INC($C$6:INDIRECT($D$3),C6))
So I'm trying to create a Forecast using historic data from 2 years. Each year's data is broken down into weeks and weeks that haven't occurred yet are set to 0. I'm struggling trying to create a formula that will automatically run a Forecast on only the weeks in the year that have occurred. I created this formula which Excel won't execute:
=UNIQUE(FILTER(WkSht!G:(VLOOKUP(F1,DH2:DI54,2)),(WkSht!A:A)=(B1)))
I'm trying to use VLOOKUP to replace the second part of a cell reference based off a lookup table. So if F1 is 25, for example, then the Filter function will be:
=UNIQUE(FILTER(WkSht!G:AE,(WkSht!A:A)=(B1))
That second formula works on its own as intended, but I'm trying to create this excel file so that it requires minimal work to update in the future and manually changing the range seems like a bit too much work to expect other people to do.
So I guess my question is:
How do I change part of the reference automatically?
Maybe I could do:
=UNIQUE(FILTER(VLOOKUP(F1,DH2:DI54,2)),(WkSht!A:A)=(B1)))
And have to lookup values contain the reference text?
Alternatively, is there a way to filter out the last of the 0's in the FORECAST.ETS function (as some values might intentionally be 0s in earlier weeks)?
To get a variable width range, you can use the construct
SomeRange:INDEX(MaxRange,,NumberOfColumns)
In your case SomeRange would be
WkSht!G:G
MaxRange would be something like
WkSht!G:Z
where you replace Z with a column that comfortably covers all your (future) data
NumberOfColumns is your VLookup (You probably want an exact match?, If so include the 4th parameter =0)
Demo:
=UNIQUE(FILTER(WkSht!G:G:INDEX(WkSht!G:Z,,VLOOKUP(F1,DH2:DI54,2,0)),WkSht!A:A=B1))
Sample data on sheet WkSht
I have one column that contains my x data and two columns that contain my y data. I would like to plot y against x, but the length of each column is dependent on a counter variable, i. I do not have experience with vba, but do with coding. Can someone outline the correct syntax to perform this task?
Please and Thank you!
You could goto your 'Developer' tab, and record a macro. While in record mode, create the graph using the data and specifications you desire.
End recording of the macro, and you will then have a template of VBA code (ALT+F11) to work with as a foundation.
It sounds like the best solution is to simply make the X-Y scatter plot ranges longer than you ever expect the data to be (Excel will ignore the blank rows).
But if you want to get fancy, you can populate your scatter plot data with dynamic named ranges that automatically adjust to the length of your data without bothering with VBA:
Create a dynamic named range (AKA named formula) representing your X data column.
Example (assuming column A, and data starting at A1):
=$A$1:INDEX($A$1:$A$1000,MATCH(TRUE,ISBLANK(Sheet1!$A$1:$A$1000),0)-1)
Change $A$1 so that it corresponds to the first row of your data. Change $A$1000 to a row number that is longer than you ever expect your data to be.
Call the named formula above "XColumn" or something similar. To make a named range, do Formulas->Define Name.
Set the X range of your scatter plot equal to:
=Sheet1!XColumn
Note that Excel's plotting window will give an error (devoid of any helpful information regarding how to fix the problem!) if you try to input the named range without the sheet name, even if the named range is scoped to the entire workbook, and even if it's on the same worksheet! -- Annoying, right?
Do this for each column and scatter plot range (Y1 = Y1Column, Y2 = Y2Column, etc.).
Note that this will not work correctly if your columnar data contains text, blanks, errors, etc., but the method can be modified to handle these issues.
To test and make sure your dynamic named ranges are being created as expected, in any cell you can enter:
=SUMPRODUCT(XColumn)
Then do Formulas-->Evaluate Formula-->Evaluate to make sure the XColumn array contains the data you want it to contain.
Optional tip: create another named range called FirstColumn set to the location of the first column, e.g. $A:$A. Make another named range called FirstRow and set it to the location of the first row, e.g. $1:$1. Make yet another named range called MaxRow and set it to the maximum length you ever expect your data to be, e.g. $1000:$1000. Finally:
Replace all instances of $A$1 above with:
INDEX(FirstRow,0,COLUMN(FirstColumn)+<DATA TABLE COLUMN NUMBER - 1>)
Replace all instances of $A$1000 with:
INDEX(MaxRow,0,COLUMN(FirstColumn)+<DATA TABLE COLUMN NUMBER - 1>)
<DATA TABLE COLUMN NUMBER - 1> will be different for each named formula (e.g. 0 for XColumn, 1 for Y1Column, 2 for Y2Column, etc etc).
Now if you ever want to create new data tables and scatter plots in different locations, instead of doing all of the work over again you can just copy and paste your named ranges and you only have to change one or two things instead of 15! Additionally, if the data ever gets longer than you expected, you only have to change one thing instead of 3.
Excel's built-in Table functionality is a great way to automatically increase a range-size when new data is added. Simply select your data, then either press Ctrl + t or go to Insert > Table. Then when you reference your new Table from the Chart it will increase as your data does.
I'm trying to create a chart with a range built dynamically using the INDIRECT function. Excel does recognize the range I am creating using INDIRECT as it highlights the corresponding range on the sheet:
However when saving the chart, I get an error message saying the function is not valid:
Does anybody know what the problem is / how to create a dynamic chart range from a specific start to specific end point?
PS: You can download the above spreadsheet here. The formula I was using:
=INDIRECT("sheet!"&E2&":"&E3)
The way you are trying to do it is not possible. Chart data range has to have a fixed address.
There is a way around this, and that's using named ranges
Put the number of rows you want in your data in a cell (e.g., E1)
So, using your example, I put Number of Rows in D1 and 6 in E1
In name manager, define the names for your data and titles
I used xrange and yrange, and defined them as:
xrange: =OFFSET(Sheet1!$A$2,0,0,Sheet1!$E$1)
yrange: =OFFSET(Sheet1!$B$2,0,0,Sheet1!$E$1)
now, to your chart - you need to know the name of the workbook (once you have it set up, Excel's function of tracking changes will make sure the reference remains correct, regardless of any rename)
Leave the Chart data range blank
for the Legend Entries (Series), enter the title as usual, and then the name you defined for the data (note that the workbook name is required for using named ranges)
for the Horizontal (Category) Axis Labels, enter the name you defined for the labels
now, by changing the number in E1, you will see the chart change:
Mine is similar to Sean's excellent answer, but allows a start and end day. First create two named ranges that use Index/Match formulas to pick the begin and end days based on E2 and E3:
rngDay
=INDEX(Sheet1!$A:$A,MATCH(Sheet1!$E$2,Sheet1!$A:$A,0)):INDEX(Sheet1!$A:$A,MATCH(Sheet1!$E$3,Sheet1!$A:$A,0))
rngValue
=INDEX(Sheet1!$B:$B,MATCH(Sheet1!$E$2,Sheet1!$A:$A,0)):INDEX(Sheet1!$B:$B,MATCH(Sheet1!$E$3,Sheet1!$A:$A,0))
You can then click the series in the chart and modify the formula to:
=SERIES(Sheet1!$B$1,Sheet1!rngDay,Sheet1!rngValue,1)
Here's a nice Chandoo post on how to use dynamic ranges in charts.
Just another answer for bits and googles..
If you still want to refer to your start and end cells, you'll need to add a separate formula for your Day Range and your Values Range. Formulas are below and the screenshot shows the formulas used.
Day Range:
="Sheet1!"&$F$2&":"&ADDRESS(ROW(INDIRECT($F$3)),COLUMN(INDIRECT($F$2)))
Values Range:
="Sheet1!"&ADDRESS(ROW(INDIRECT($F$2)),COLUMN(INDIRECT($F$3)))&":"&$F$3
Then add two ranges referencing the INDIRECT values of those cells
Press Ctrl+F3, Click New, and add a new range with the name "chart_days", referring to =INDIRECT(Sheet1!$F$4); and a new range with the name "chart_values", referring to =INDIRECT(Sheet1!$F$5)
Finally, in your chart, add a series that refers to =nameOfYourWorkbook!chart_values
and Edit the category to refer to =nameOfYourWorkbook!chart_days
I use OFFSET to create a defined name formula so that I may define all the ranges for the data, allowing me to have a starting a ending date (or the beginning and ending position of any data set).
For a simple graph, I define the name CategoryLabels as follows:
= OFFSET($A$5; (InicitialMonth-1); 0; LastMonth - (InitialMonth-1))
and DataCars as follows:
= OFFSET($B$5; (InicitialMonth-1); 0; LastMonth - (InitialMonth-1))
You will have to define as many names as Series you want to include, following the same procedure. In this simple case, I only included Car sales.
Initial Month and Last Month are Range Names defined for single cells used to indicate which months of the graph will be included (from starting to ending months).
Remember, as explained by Sean Cheshire and others, that to use the names for the chart values, the name of the spreadsheet must be included.
According to the formula you have shown: =INDIRECT("sheet!"&E2&":"&E3)
you are not naming the sheet correctly.
I would have thought it would be Sheet1! or Sheet2! etc.
Your formula resolves to =sheet!E2:E3 which is not a valid address. The error message you are getting means Excel cannot resolve the input to INDIRECT. INDIRECT is a valid function so the argument you offer it must be invalid.
All of the above answers which state the sheet name have corrected your error but do not mention it... ;)
Named formula with Indirect functions DOES NOT WORK IN CHARTS. It works in other froms as your desired dynamic source will be highlighted, but when you it in chart, it would not be evaluated. Hope Microsoft put a fix on this.
When a line chart's range is a named variable, and the variable has INDIRECT() references through a cell to a range, then the variable must have at least 2 INDIRECT()s separated by a comma.
i have a named range that refers to range D3:I23 and this range is well-defined for some automation purposes.
Recently i had an update that required me to redefine this range as F3:I23 and exclude, initially, columns D & E. But further in the various logic coding, i need to include E for evaluation (turning dynamic data to static data).
Was thinking of using Resize but didnt seem right. Also thought Offset but that moves the whole range forward or backwards. I basically need to resize the range back 1 column while retaining the original defined range
In essence i need the named range to be defined as F3:I23 but during this one code segment i need the range to be evaluated to E3:I23.
Any thoughts, or combination of Range properties to use in VBA? At the point that i am passing the reference, it is being stored in a Range object, so any chained set of properties is fair game.
Please try to apply the KISS policy when answering. Doesnt need to be an overly complex formula, as i am not guaranteed to be the one supporting the end result.
As Rachel indicated... this should do the trick assumes your named range is defined as namedRange:
Set neededRange = namedRange.Resize(namedRange.Rows.Count, _
namedRange.Columns.Count + 1).Offset(0, -1)
Resize to increase the columns included by 1, then offset the entire range by -1 column to get your neededRange.