Assign default value to cell in Excel dropdown and should accept any other value - excel

I am using Excel sheet as test data source for my automation scripts and I want to reduce test data creation time by selecting default values for cell.
Query:
I have column as Company name so by default I want to auto populate value as "XYZ" for all cells which are null.
Tried two options:
Data validation list: I have inserted list with my default value as XYZ however if I want to add some other value I have to go back and edit the list. Want to avoid this manual effort.W ith auto-population it should allow user to enter any value.
Added formula: =IF(A2="","XYZ")
A (Company ID in Excel). It shows an error-Try moving your formula to different cell
Could anyone help me to solve this.

Related

Excel Data Validation (List) with IF Contains text

I am trying to do a data validation list where the drop down only contains text like "US" or "EU" to isolate the PO numbers. The table column I am pulling from can have things like "US12345" or "EU76543" or "ID10987". I need the list to only show the items that have that US in them.
I tried:
=IF(INDIRECT(Table[PO_Number])="US*",INDIRECT(Table[PO_Number]),"")
This gives a Value Error.
Is what I am trying to do possible? If so, how?
You'll need to create the desired filtered list somewhere within the workbook, as dynamic lists cannot be entered directly within Data Validation.
For example, assuming you have Office 365, this formula in cell D1:
=FILTER(Table[PO_Number],LEFT(Table[PO_Number],2)="US")
will spill all matching entries.
(Amend the condition - here checking if the initial two letters of the PO Number are "US" - as required.)
For the Data Validation, you can then use the List option and set the Source to:
=$D$1#
Include the sheet name in the above expression if the cells being validated are not in the same sheet as the FILTER formula.

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

To create dynamic dropdown list in excel 2013

I have one sheet containing the table name customer_id and Project_id.For each customer id various projects are displayed.when i try to create data validation by selecting all those it is not coming.for ex.
Customer_id Project_id
1 1.1
1 1.2
2 2.2
2 2.3
and like that.please tell me some solution.
This really depends on what you want exactly, but since your question is not that elaborate, I guess you mean this?
You can create a data validator from data in your worksheet in the following way:
Select the sheet you want the validator to be on
In the ribbon, click the data tab, and then Data validation
Select 'Allow List'
in the Source bar, select the cells with the allowed values
Another way, is to create a data validator using a vba or vb.net macro. In your macro say:
Dim range as Excel.Range = listSheet.Range("A1")
range.Validation.Add(Excel.xlDVType.xlValidateList, Excel.xlDVAlertStyle.xlValidAlertInformation, Excel.xlFormatConditionOperator.xlEqual, "Option1; Option2")
I guess what you want are two dropdown lists, the second depending on the value selected in the first one? (please elaborate your questions some more). To do that, I suppose there are other ways but this is what I usually do:
Take into account that I always use names to refer to ranges instead of references, to improve readness. If you have doubts to do it, read Use names in Excel formuas
Create a table or range somewhere in your book with one column with the master values.
I have named the range with the values master_list
Create a table or range somewhere in your book with two columns. The first column contains the master/look-up value and the second the dependent values.
I have named the list of look-up values (this is, the values in the first column) as dependent_list
I have named heading to the cell above the dependent_list (for example, if the dependency table starts in A2, the heading is A1
Order the lists
The master_list is ordered as you wish values appear in the dropdown list.
The dependent_list must be ordered by the values in the first column (master values). It doesn't matter if the order is the same in the master_list and the dependent_list, but identical values in the master column of the dependent_list must be together.
The order in the second column of the dependent_list will determine the order in the dependent dropdown list.
Optionally you can define a message to display in the dependent_list when there is no master value selected. I have named it msg_error.
Click on the cell where you want the master dropdown, ant go to the Data Validation menu, where you select:
Allow: List
Source: Add the formula =INDIRECT("master_list")
I have named the cell where the master dropdown list as key_value
Click on the cell where you want the dependent dropdown, and then go to the Data Validation menu, where you select:
Allow: List
Source: Add the formula =IF(key_value="";msg_error;OFFSET(heading;MATCH(key_value;dependent_list;0);1;COUNTIF(dependent_list;key_value);1))
Note that Excel functions are language dependent of the language and I have translated them to English, so maybe there are mistakes.

Array Formula in defined name only returns single value instead of array

Here is what I'm trying to achieve (in Excel 2016):
I have a sheet (named 'Relations') in Excel, containing a table (named 'Relations'), which contains a list of relevant contacts for my business, with name, addres, etc. The table also contains a column 'Code' to distinguish different contacts by a code.
On a separate sheet I would like to use a drop-down list with all contacts that have a code that starts with "DHR". My approach:
Create a defined name (DHR_CONTACTS) that returns a list of the contact codes that start with "DHR".
Create on the separate sheet a data validation (list) with a reference to the defined name.
Now I have a formula for the defined name (DHR_CONTACTS):
=INDEX(Relations[Code];SMALL(IF(LEFT(Relations[Code];3)="DHR";ROW(Relations[Code])-ROW(Relations[#Headers]));ROW(OFFSET(Relations!$A$1;0;0;COUNTIF(Relations[Code];"DHR*")))))
When I enter this formula using CSE in a range on my sheet it returns the expected results - a list of all codes that start with DHR, no matter how the table is sorted.
When I enter this formula in the defined name (DHR_CONTACTS) and create a data validation for a cell: =DHR_CONTACTS, my drop down list only shows the first code from the table that corresponds to the criteria.
Can anybody tell me if what I'm trying to do is even possible, and if so, what I'm doing wrong?

Excel Data Validation List using formula with filtering

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.

Resources