Excel Function to Exclude rows based on certain values - excel

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)))

Related

Excel Creating New Sheet with Summed Data from related sheet

Lets say I have the following on a sheet.
By some means, I want to either replace this, or preferably, create a new sheet, with the following data. Notice, that PO# is out of the picture, and a summation is done on rest of the fields. Is there a way to easily do this?
The end result has to be data in excel grid like below (preferably on a new sheet). This can possibly be some macro or some other technique I can use to easily create this....
You can easily do this with SUMIFS() or a Pivot Table.
For SUMIFS() the below equation will give you the sum for W.PS123 Product A. Modify as needed for your other criteria by swapping AR and product number (both housed in quotes in below formula, you can also set these equal to a cell range that contains desired criteria).
If you have a set number of "ARs" and Product Numbers, you will only need to build this table once and the equations will automatically update as your raw data changes.
=SUMIFS(C:C,A:A,"W.PS123",E:E,"A")
Alternatively, you can build a pivot table and just refresh this every time your data updates (or create a worksheet_change macro to refresh the table automatically when your data changes).
To build your pivot:
Highlight your table array (In your example, Col A-D)
Insert > Pivot Table
Drag AR to Rows
Drag PRODUCT to Rows (Below AR)
Drag QTY to "Values" and change the field to "Sum" rather the default count
Format to taste

Excel apply formula after pasting table

Is there a way to create an excel template, which automatically applies a formula if a certain column is inserted? The use case would be:
User copies a table from a desktop program (CSV or Tab separated)
Pastes the table into the excel template
Somehow the column's header gets matched (header's name is fixed)
Multiply the column values with a fixed value (like 1.25)
The problem is that the column could be in different indexes and the formula should apply to all the rows, not just fixed ones, but my main problem is how can I get a copy-paste event and find the column.
Edit.: I can only do this with VBA (never used it before)?
Assuming the column header is constant you could insert a table with "dummy" headers and a calculated column using the header name as a reference
In the example I have put a formula in the Calc column. I've put the Calc in column G assuming your maximum import columns are six and because it's good practice to do your calculations from left to right.
You could move the Calc to column A and reduce the "dummy" columns to just 1 with whatever your desired heading is.
To make a template, delete row 3 and clear out the dummy data, just leaving the calculation(s) and save as a .xltx in your profile template folder (wherever that may be in your versions of Windows/Office).
When you paste in your import data the table will extend down and copy the formula(s) automatically. If you have moved your calculation(s) to the left of the table, the table will resize to the right to accommodate all your imported columns.
While the MyHeader column in your template may be over-written, if it can still be found in `Table2[#Headers] the formula will still work.

Automatically expand range of Excel array formula (without macro)

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.

Excel Dynamic Drop Down List

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.

Excel formulas and conditional lookups based on multiple criteria and sheets

I have 2 sheets:
sheet_a is a styled print-ready layout for a single data record
sheet_b is a bulk data table which is continually growing. Each row corresponds to a single complete record
Currently I am using a VLOOKUP to collect the data from sheet_b and put it in the respective cells in sheet_a. I have a drop down list on sheet_a which allows me to select a single record at a time to view.
Now I want to introduce a second drop down list to sheet_a where I want to select 1 of 4 specific conditions relating to the value of a cell in a specific column of each record on sheet_b.
I only want the entries that meet this condition in sheet_b to be made available in the range of records I can view on sheet_a.
Can anyone help?
As I understand it, you are looking for a way to filter the list that is used in the drop-down on Sheet_A.
add a column to the source data and calculate or mark manually which of the four conditions the record belongs to.
on Sheet_a add a drop-down field where the user can select from the four conditions. Name this cell "criterion"
in the source data table, add a column with a formula that returns the row number if the current row matches the selected criterion. Something like this copied down
=IF(B2=criterion,ROW(),"")
create another helper column that contains only the items that match the criterion using a formula like this and copied down
=INDEX(Data,SMALL($E$2:$E$18,ROW(A1)))
use a dynamic range name called "FilteredList" that contains only the values of the result list, not the errors. The formula for "FilteredList" is
=Sheet1!$F$2:INDEX(Sheet1!$F:$F,MATCH("zzzzz",Sheet1!$F:$F,1))
change the drop-down that is currently used to select a record to source its values from =FilteredList

Resources