Problem
How can I automatically add rows to an array formula as I manually add rows to a table? Similar functionality seems to be offered by Google Docs at https://support.google.com/docs/answer/3093275?rd=1, and is adapted for Excel with a macro at http://www.wilmott.com/messageview.cfm?catid=10&threadid=62734. However, using this macro requires enabling Microsoft Scripting Runtime, which I'd rather not do, and would also be difficult for the end-user to maintain. I'm running Excel 2013.
I am creating this worksheet for an end-user who may not be knowledgeable about VBA or array formulas, but will need to add items to a Validation table (described below). As the user adds table rows, my data validation range and its array formula are not automatically increased in length, and it's probable that the data validation will no longer show all acceptable values.
Setup for Filtered Data Validation
You can view my stripped-down worksheet with macros disabled here. Data validation on the Process column in the Main table will only show values that are currently showing in the Testing Process column in the Validation table. Slicers are included for ease of filtering.
Using help from http://www.contextures.com/xlDataVal02.html and some other sources, I have created a table named Main_HIGHLIGHT with data validation that only allows the visible/filtered values of a column in a second table named Validation.
The second table has three relevant columns, Visible, Category, and Testing Process. The table is filtered with a slicer on the Category column and the data validation returns values from the Testing Process column. A three-step process is used to prevent filtered values from appearing in the data validation:
Cells in the Visible column shows a blank if the table row is filtered out, and show the value of Testing Process if it's not filtered out. Its formula is:
=IF(AGGREGATE(3, 5,[#[Testing Process]])>0,[#[Testing Process]],"")
An array formula directly to the left of the table, but not a part of the table, takes the range from Visible and sorts it so that all the blank cells are at the bottom of the range, and all the cells with a value are at the top. It fills a range with width 1 and height equal to the number of entries in the table. This range is given the Defined Name Visible_Tests_with_filtered_removed. The formula, entered with Ctrl-Shift-Enter as usual, is:
=INDEX(Validation[Visible],
SMALL(
IF( Validation[Visible]<>"",
ROW(INDIRECT("$A$1:$A$"&COUNTA(Validation[Category]))),
""
),
ROW(INDIRECT("A1:A"&COUNTA(Validation[Category])))
)
)
A Defined Name, Visible_Tests_with_blanks_removed, is created that includes only the values from Visible_Tests_with_filtered_removed, not any blanks or errors. Its formula is: =OFFSET(PPRNT!$A$34,0,0,MATCH("*",Visible_Tests_with_filtered_removed,-1),1)
Potential Solutions
Ideally I'd like to add the array formula to the Validation table, since that would automatically copy the array formula to any new row as it was added. When I try doing this, however, I get the error that "Multi-cell array formulas are not allowed in tables."
Alternatively, perhaps I could put this entire range into another Defined Name like Visible_Tests_with_blanks_removed, whose values are not actually located in cells on the worksheet. I don't know
If all else fails, I could use the macro I linked above, but it seems to me it shouldn't be this hard and I would probably just include instructions for expanding the Array formula in the HowTo tab.
Thanks #OldUgly for a bump in the right direction.
Download the example workbook from OneDrive at https://1drv.ms/x/s!Ak4Lq2gGjO8hleIyd60JuPkctlDhGw, but note the online preview doesn't support Data Validation! You must download the file to see it in action.
This three-step process creates the proper list for data validation, and it's part of the table so it updates automatically. Note that the CSE formula I used in my original question was multi-cell (select a bunch of cells, then enter the formula and hit Ctrl-Shift-Enter), but those aren't allowed in tables so this solution uses a single-cell array formula, which is automatically copied to every cell in the column in the table.
Create a Visible column on the table to determine which rows are currently hidden. This is a normal formula, not a CSE formula.
=IF(AGGREGATE(3, 5,[#[Testing Process]])>0,TRUE,FALSE)
Add a Filtered List column to the table, and enter this single-cell CSE formula (which should get automatically copied to the rest of the cells in the table, just like any other table formula). If you press Enter instead of Ctrl-Shift-Enter, you'll get the #NUM! error for all but the first cell.
=INDEX([Testing Process],
SMALL(
IF([Visible], ROW([Testing Process])-ROW(Validation[[#Headers],[Testing Process]]), ""),
ROW([#[Testing Process]])-ROW(Validation[[#Headers],[Testing Process]])
)
)
Create a Defined Name Testing_Processes_for_Data_Validation (Formulas->Define Name) with the formula =OFFSET(Validation[[#Headers],[Filtered List]], 1, 0, MATCH("*",Validation[Filtered List],-1), 1) so that the Data Validation doesn't have a bunch of #NUM! errors at the end of it.
When activating Data Validation on a cell, set Allow to be "List" and Source to be =Testing_Processes_for_Data_Validation.
And that's it! This creates an automatically-expanding dynamic list based on the filtered column of a table, and removes blanks and errors from that list.
Related
I to exclude rows in a excel table based on certain values
For example:
I need to exclude all rows if column A is equal to any of these numbers ( 5840,4302,4432, and so on)
As the table data will be huge to filter only the data that I want.
One way is to exploit Excel Table feature together with the FILTER() spreadsheet function. NB. You will need a relatively recent Excel version for this. Using a Table provides some extra useful functionality (such as automatically adding rows and allowing reference by column name).
The OP's input data may already be a Table, if so, this first step can be skipped.
Put the input and filter list into tables. Excel help page. After the table has been created I have used the Table Design menu (which appears in the menu bar when a cell in the table is selected) to turn off the row banding format and header filters. This is also where you can rename the Tables. I have named them "Input" and "Exclude"
For the filtered output, choose where you want the output to start (cell H3 in my example), and enter a formula to copy the headers: =Input[#Headers]. Of course you can copy and paste the headers manually if you like. Here I've used the Format Painter to copy across the cell formats for the headers.
In the next cell down (H4 in my example), enter this formula: =FILTER(Input,(LEN(Input[ID])>0) * ISERROR(MATCH(Input[ID],Exclude[IDs to exclude],0))).
You should be able to add or delete new rows (right-click in the Table and choose Delete) in both the Input and Exclude tables, and the output should react (if you have Calculation set to Automatic).
NB. The Output range is NOT a Table. Excel doesn't let you convert dynamic ranges into Tables.
EDIT: If you don't want to use Tables, you can simply supply the ranges as the parameters to the FILTER function.
In this example =FILTER(B4:D13,(LEN(B4:B13)>0) *ISERROR(MATCH(B4:B13,F4:F5,0)))
I am currently using Index,Match to match records from one sheet to the other. Works great, except when I have multiple records with the same identifier. Let me explain:
The sheet named Open Leave Report contains the raw data (lookup values), while the sheet named Open Leave Capture contains the scrubbed data. So my formula looks like this
=INDEX('Open Leave Report'!O:O,MATCH('Open Leave Capture'!C9,'Open Leave Report'!B:B,0))
Works great, except when I have the following:
Column B Column O
Employee ID Continuous or Intermittent
1646484 Intermittent
1646484 Continuous
So when I type the Employee ID in the Open Leave Capture it always brings back the first row, but it ignores the second record. It looks like this:
Employee ID Type
1646484 Intermittent
1646484 Intermittent
Is there any way I can format my Index/Match formula to bring back both records?
I hope I explained this well
Don't use INDEX and MATCH for this...use PivotTables instead.
Whenever I want certain records from a list to appear in a different place, I turn my source data into an Excel Table, and make a PivotTable out of it, and then filter that PivotTable to show just the items I'm interested in.
No formulas, and as soon as you refresh the PivotTable it will automatically pick up any changes to your source data. Unlike formulas, which can be overwhelmingly complex to pick apart, and rely on you remembering to drag the formula down the page in order to ensure you capture any new data.
The solution is far simpler if you convert the source data into a table. Select the source data then use Insert > Table.
This solution has the following assumptions:
Source data has columns named "Employee ID" and "Type"
In the destination, the IDs to be looked up start from cell A2
In the destination, the values to be returned start from cell B2
This is formula to put into cell B2. This is an array formula. You need to double click into the cell, paste the formula, then save it by pressing CTRL+SHIFT+ENTER. You can then fill it down as far as you need to go.
=IFERROR(INDEX(Table1[Type],SMALL(IF(Table1[Employee ID]=A2,ROW(Table1[Employee ID])-ROW(Table1[[#Headers],[Employee ID]])),COUNTIF($A$2:A2,A2))),"Not that many")
I'm using Excel 2016. I have a table with headers and when I plug in a formula, Excel is automatically replicating the formula to all other cells in the column. While that would normally be fine, it's wrongly calculating the table headers. I thought I could just change the top row to exclude the header but Excel updates the rest of the column which I don't want.
I would like to either turn this automatic formula replication feature off or figure out a way to customize the formula in the top row so it doesn't calculate the header value.
Here's the formula I'm using and I didn't do anything special with the table outside of add a 'Totals' row:
=SUM(B2+C1-D2)
You can stop creating calculated columns. The option to automatically fill formulas to create calculated columns in an Excel table is on by default. If you don’t want Excel to create calculated columns when you enter formulas in table columns, you can turn the option to fill formulas off. If you don’t want to turn the option off, but don’t always want to create calculated columns as you work in a table, you can stop calculated columns from being created automatically.
Turn calculated columns on or off
1) On the File tab, click Options.
2) Click Proofing.
3) Under AutoCorrect options, click AutoCorrect Options.
4) Click the AutoFormat As You Type tab.
5) Under Automatically as you work, select or clear the Fill formulas in tables to create calculated columns check box to turn this option on or off.
Stop creating calculated columns automatically
After entering the first formula in a table column, click the AutoCorrect Options button that is displayed, and then click Stop Automatically Creating Calculated Columns.
In Excel 2016/365 you can also change a cell you want, let it auto-populate the rest of the column, then Ctrl+Z, this will undo auto-populate but keep the new formula/text you just changed in that one cell.
First, why do you wrap a simple formula into a SUM function? I always wonder why people do that when it's much shorter to write =B2+C1-D2 instead.
Second, if you used the true capabilities of SUM() then text, i.e. your column header, would be ignored instead of throwing an error. The + and - operators don't tolerate text, be it in a table or not. You could rewrite your formula to be
=Sum(B2,C1,D2*-1)
Third, be aware that cell referencing like that will behave erratically when you insert rows into the existing table (between existing rows). The row references will be off for anything below the inserted row and you will need to manually copy down the formula again to get correct results.
In order to get a formula that does not require adjusting, you may want to use structured referencing, where each row has exactly the same formula, instead of cell references, where row references are adjusted in each row. A possible formula for this would be (if your columns are labelled data1, data2 and data3 for columns B, C and D):
=SUM([#data1],OFFSET([#data2],-1,0),[#data3]*-1)
To get the data from the row above, Offset() is used on the cell in the current row (using the # sign), with a negative row offset. Keep in mind that Offset is volatile, which may slow down very large datasets.
Adjusting AutoCorrect options is not optimal. You can do it on a col by col basis by:
let the column autopopulate your formula
delete any number of values in the autocalculated column (just one will do the trick).
adjust formulas in the column as you wish
Only able to test in Excel 2013.
May be a little late to open this query - but a couple of points:
formula replication does not work if there are already different formula in the column - may need 3 different formula before Excel says it cannot guess which formula to replicate
a solution could be to add 2 dummy rows at the top which will then prevent the replication - the benefit of this is that you are not disabling replication for any other tables that may be in the workbook; and I'm not sure if the setting may also inadvertently be copied to other new workbooks you create whilst you have the first workbook open
finally, the old chestnut that =A1+B2 etc creates an error if A1 or B2 are not numeric; whereas =sum(A1,B2) works differently in that text will be ignored and effectively treated as zero
If your reference has letters in the middle these technics won't work. To add a zero before the reference in that case, create a new column next to it, add "0" to all the cells next to the references, add another column and use the function "concontenate" or whatever between the "0" cell and the one with the reference.
Not only that, the =len function will correctly tell you the # of digits on references with letters in the middle (because excel does not view them as numbers per se, but rather text/general format) while on other references with 0s added before them with formatting this doesn't happen.
Eg: 012345 =len gives 5 digits / 01A345 =len gives 6 digits
I have two tables that get dynamically created from a database query; the first table is the source of the drop-down list, and the second is the table that I will apply the drop-down list via data validation. First table:
and the second table:
What I need, ideally through just Excel formulas, is an intelligently designed drop-down that shows only the dimension values associated to the dimension in question.
So in cells B3:B10, the drop-downs would show a,b,c. In cells C3:C10, the drop-downs would show 1,2,3. In cells D3:D10, the drop-downs would show x,y,z. Etc, etc.
I need this to be dynamic in the sense that a week from now my DB query may return a fourth dimension that would need to follow the same approach.
Not sure if this is even possible without writing some VBA, but I figure I'd see if anybody has any creative ideas. Cheers!
You have to use Name Manager and =INDIRECT() formula to achieve that.
First download the sample file.
Sample File
See this tip (By me). It will help you to see screenshots step by step. Link is here
Now in-case of your data you have to use some formula to filter data automatically when new data come. So that new data can organize for dynamic combo boxes. I can also do that for you if you are not able to do that. Then share your sample workbook with me.
It is very possible, but not simple. There are a several ways to implement this, depending on your requirements, how dynamic it needs to be, and the expected structure of the data (as I mentioned in a comment).
I will give one possible solution, that is mostly dynamic, and is the simplest to explain. You can use a similar logic to make it all dynamic.
This solution will retrieve the data from table #1 according to the dimension name, assuming it is not sorted, and return the values in the order they are given in the table.
For some of the ranges I create names for simplicity, and some are mandatory. In order to follow the formulas logic you need the named ranges I use.
Create named ranges for table #1: (Either by using the Name Box or using the Name Manager Ctrl+F3):
For the data in the column Dimension: DimName =B3:B11
For the column Dimenstion Value: DimValue =C3:C11
Create dimension values lists in a new sheet:
Put the dimension name in B2 ="Customer". (The available dimension names can be created dynamically as well, but I'm skipping this part for simplisity).
B3 (array formula - Ctrl+Shift+Enter) =IFERROR(INDEX(DimVal,SMALL(IF(DimName=B$2,ROW(DimName)-ROW(INDEX(DimName,1))+1),ROWS(B$3:B3)),1),""). This formula returns the k-th value for the "Customer" dimension.
Copy B3 down to as many rows you think you'll need. Let's say B4:B10, so B3:B10 will have the array formula. The first cells will have the available values and the remaining cells will be empty because of the IFERROR function.
In B1 we will count the available values using the formula =SUMPRODUCT(--(B3:B10<>"").
Do the same for "Product" and "Geography" in columns C and D.
Create dynamic named ranges for the lists: (using the Name Manager Ctrl+F3)
For the lists' data DimLists =B3:D10.
For the lists' headers DimListHeaders =B2:D2.
For the lists' counts DimListCounts =B1:D1.
*These names are mandatory for the data validation to work in another sheet.
Set table #2 data validation list sources:
Select B3:B10 in table #2.
Go to Data > Data Validation, and select Allow: List.
Put the following formula in the source: =OFFSET(INDEX(DimLists,,MATCH(B$2,DimListHeaders,0)),,,INDEX(DimListCount,,MATCH(B$2,DimListHeaders,0))). This formula finds the correct list in DimLists according to the column header in table #2, and also sets the returned range height according to the list count.
Hope this helps.
I have following workbook:
Worksheet Accounts:
Worksheet Posts:
I would like to know if it is possible to define Data Validation of type List to entire column B in sheet Posts using formula, so that Data Validation popup shows only Account Ids from Accounts sheet which Website column matches Website column of a selected row in Posts sheet and which have value Active in Status column?
In SQL-ish or LINQ-ish words:
SELECT Id FROM Accounts WHERE Website =
#SelectedPostRow.Website AND Status = Active
Marks on the second image shows which values should be shown in a drop-down.
Yes you can do this, but it requires some supporting setup.
First for each of your website options, you need to create a named range for the options that would be in the drop down you are seeking to create.
To do this, just highlight the list of cells and right click, the choose Name a Range
Then you need to create a lookup list for your website names to the named range possiblities
Then in your data validation source use a forumla like this:
=indirect(vlookup(a1,$i$8:$j$13,2,false))
then whala, the dropdown list changes based upon the website value.
Now if you are also needing to automate the named range bits, you could change them to encompass entire columns and then use a pivot table to pull in the data. Would just need
an independant pivot for each website option.
Each time you pulled in fresh data you would need to refresh the pivots, but it would function.
This problem need a bit of a preparation.
In the same sheet, or in another, copy your data (or add the relevant cells)
In column A you have a number that could be ranked.
I obtained it with (cell A2):
=IF(C2=$J$2,1,0)*IF(E2="Active",1,0)*ROW()
In column B rank the number and exclude the unwanted rows (B2):
=IF(A2=0,0,RANK(A2,A:A))
Then you can VLOOKUP in column H, using a enum in column G (manually entered). The formula for H1:
=IFERROR(VLOOKUP(G2,$B$2:$D$9,3,FALSE),"")
Now you could set your validation based on column H
PS: there could be small errors in the formulas as I have translated them from italian and I cannot test in english.