(excel Data Validation:) How to apply multi conditional and interdependent data validation - excel

I have two columns (Increment Rating & Promotion) where a user has to provide her input.
The "increment rating" input is restricted from Min (0.5) to Max (4.5) and the "Promotion" input is restricted to "Yes" or "No".
I know that for, Increment Rating I can apply the decimal validation criterion between Min & Max values, and for Promotion, I can apply the "list" criterion.
However, IF the user has entered the max value (i.e. 4.5) in the first column (i.e. Increment Rating), then Promotion must not be "Yes". It has to be either No or Blank (And I also need to show an error message saying that "This is not allowed"). On the other hand, IF the user is filling the second column (i.e. Promotion) before the first column and selects "Yes" as input then Increment Rating can not be more than Max-1 (i.e. 4.5-1=3.5) and need to show an error message here as well.
Is it possible with data validation custom formula? Or someone can help with #VBA.
Thanks.

You can create a table featuring the allowed data values for each input row and then refer to that table with relative references (i.e. no row fixing with $).
Here below is an example of such a table with formulas that adjust the allowed data values conditional on the input already provided. Note that the rows in the 'Source' section of the data validation window are not fixed.
Such that, when selecting the drop down window of those cells that have a list, you can see how the list is conditional on the table on the right.
If the input is done one cell after another (and not through copy and paste over both columns and once) an error message should not be needed since both columns have data validation restrictions conditional on one another.
You do not have to re-do the data validation for every row but simply select all input rows of one column and use relative reference instead of absolute reference in the 'Source' field of the data validation window.

Related

Is it possible to not allow null values for particular in an excel data entry spreadsheet (VBA?)?

I have an excel worksheet where I have a number of manual data entry and calculated columns, which is to be filled in line by line with the rows filled from left to right.
I have a few columns which I want to ensure are not left blank as this data entry is carried out.
E.g.
Here I am entering data from left to right on the 3rd row and want to ensure that if the person doing the data entry manually accidentally skips the "Unique ID" column and tries to fill in "Type" first, they will be forced back to the "Unique ID" cell or at least experience a pop-up to tell them to enter in "Unique ID" first.
Is this something that can be done?
This can be handled in different ways; one of which is adding a simple data validation rule.
Add a data validation rule to the 2nd cell that checks whether or not the prior field is blank. If so, don't allow entry in the cell and display a pop-up message.
Data validation rules just have to have a a TRUE result.
Add this formula to a custom data validation rule on the 2nd cell.
not(isblank(c7))
Then, if the user tries to populate the 2nd cell while the 1st is still blank, the user gets an alert message and then the cell contents is cleared.
UPDATE #1
If you need to create a dependency for a data validation list you could add a table to a new sheet to act as your list handler. The basic theory is that one column is filled with an index of each row, a 2nd column checks to see if the criteria has been met, a 3rd column contains every item that could appear in the list and a 4th column is a formula that builds the list based on all of the criteria.
Here is a working example. It's a little different than your scenario but it shows the premise. The example below builds a list of items that can only be selected once. Once the item is selected in a cell, it does not appear in the lists for other cells.
t_FinalPlans_Medical is the name of the table.
medicalRow_FinalPlanSelections is a named range containing the cells that have the data validation rules/drop-down lists.
dataValid_FinalMedicalPlans_OptHeading is a named range holding the column header.
INDIRECT("t_FinalPlans_Medical[[#Headers],[Column1]]")
dataValid_FinalMedicalPlans_OptList is a named range for the index column.
INDIRECT("t_FinalPlans_Medical[Index]")
Index Column Formula IF([#[Unselected Plans]]="","",MAX($D$7:D7)+1)
Final Plan Selections Column
Each cell in this column is manually typed.
Unselected Plans Column Formula
IF(COUNTIF(medicalRow_FinalPlanSelections,[#[Final Plan Selections]])=0,[#[Final Plan Selections]],"")
Column1 Formula
IFERROR(INDEX([Unselected Plans],MATCH(ROW()-ROW(t_FinalPlans_Medical[[#Headers],[Column1]]),[Index],0)),"")
Formula used as Data Validation (dynamically expands) OFFSET(dataValid_FinalMedicalPlans_OptHeading,1,0,MAX(dataValid_FinalMedicalPlans_OptList),1)
https://trumpexcel.com/excel-drop-down-list/

Excel Dynamic Data Validation Based on Adjacent Column

I am trying to piece together some VBA code that would apply data validation (creating a list to use) to a cell based on the value of the cell next to it. I have this functionality working in a Google Spreadsheet which I just linked but I don't know anything about VB so I'm struggling with this.
The layout is a little odd with the spreadsheet since the sheet(s) that need this validation have the headers of the rows starting at row 2.
The basics of what's going on is:
The header of the column that is determining the validation is called "Attribute Group". I want to avoid needing a fixed position so I went with the header name instead of a column index
When a value changes in "Attribute Group" the cell adjacent to it to the right will have a dropdown created with values corresponding to the value in "Attribute Group"
Please check out the linked spreadsheet to see this functionality in action. I'm trying to get as close to this as possible in Excel.
Edit: The main question is: how do you create dynamic data validation in Microsoft Excel?
Unfortunately I don't have time to get this working exactly as I would like.
The solution I have now was to create tables for each column that had data that would correspond with the appropriate "Attribute Group".
Insert > Table
Rename table to match corresponding "Attribute Group" value, removing spaces and special characters
Remove duplicates to get rid of most blank cells then Resize Table if needed to get rid of any others
Then I added data validation in cell E3 using =indirect() as well as substitute() since my "Attribute Group" values had spaces and special characters.
Data > Data Validation
Under "Settings" I used "List" in the Allow section
The source was =INDIRECT(SUBSTITUTE(SUBSTITUTE($D3," ",""),"&","And"))
Then I copied cell E3 and pasted all the way down.
This method solves my current issue but doesn't allow for the level of flexibility that I was hoping to accomplish.
Use a named range (Eg "MyDataRng") for the range of cells in the Attribute Group then in a list type data validation enter =MyDataRng

Restructuring data in excel

I am trying to condense data in a specific way. I want any occurrences of the number 1 in each column to show up as 1 (regardless of how many times it occurs) with the corresponding site, in the corresponding column. Some sites occur multiple times in the original data, and I want to make it so that only one of each unique site shows up in the resulting data table with a 1 for the corresponding column if there any 1's in the column from the original data.
I would think it would be a vlookup function, but I have tried many different things and I am really stuck on this.
Image of original data and what I am trying to do:
Thank you
This assumes that your data set only contains 1 or blank and this approach uses a Pivot Table with MAX function. Below are details in case anyone doesn't know Pivot Tables.
Select a cell in your data and insert Pivot Table. Note, I added a title for column A, as you need that in the Pivot Table.
Click in the created Pivot Table and the PivotTable Fields dialog should pop up. If not, right click in Pivot Table and select Show Field List.
Drag the Field names (Code, a, b,& c) down to the appropriate blocks below. (Values under Columns will be created for you.)
Click on the drop down arrow next to each field name and select Max. That will rename it to "Max of ...". If that bothers you, then you can type the name you want into the Custom Name field. Note, it will not let you type the same name as the field name, eg a, but it will work if you put a space in front of it.
Given that the Pivot Table would be a lot of work for a large number of columns, here is a formula based approach. Put this formula in cell G2, then drag it down and across to fill your new table.
Note, you will have to populate all codes that you have in column F. And if any new codes are added later you will have to keep this updated. One of the advantages of a Pivot Table is that it will do this for you.
I know that you won't be putting this in these cells, so adjust accordingly. In fact, I would recommend this be in another sheet.
=IF(COUNTIFS($A:$A,$F2,B:B,1)>0,1,0)
COUNTIFS($A:$A,$F2,B:B,1)
This will count each occurrence when the value in column A matches your code $F2 AND the value in column B equals 1.
If that count is >0, then you know that at least one match was found and the IF will return 1, otherwise 0.

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.

how to call associating values to drop menu choices

i have a table in exel
column 1 = bolt sizes in imperial values
column 2 = bolt sizes in metric values
now a called the column 1 ''bolt_size'' and created a drop menu where you can choose between all the different possible sizes (in imperial) but as for the rest of the sheet i need the metric values.
what i have been tryinh to do is once the choice in selected in the drop menu, the second value (the metric one) appears in a chosen cell where the rest of the sheet will call that value for further calcuations.
I have sucessfully made that cell display 1 - 10 (when choosing from the drop menu) instead of the actual values associated with the bolts.
Please help guide me in the right direction
If this is a Form Control/ Combobox, and you have specified its Cell link, then it will display the index number of the selected item, rather than the actual value. In a cell enter the following formula that uses the linked-cell's value to retrieve the text from the input range:
=INDEX(C2:C4,D6)
C2:C4 is the Input range and D6 is the Cell link.
If you are not using a Form Control then you'll need to clarify your question.

Resources