Excel - 2 data validation in the same cell - vba

I want to combine 2 data validation into one cell. I can do it with separate cell, but had no idea on how to combining them.
First Validation: a list contains certain options for user to choose, and an others if it is not inside the list.
When Others is being selected, User can input their own data.
First Validation Setting
Second Validation: a cell that needs to starts with a certain format, else error message will appear. e.g. users can are only to allow to input in this format ABC xxxxx
Second Validation Setting
I want to combined the list validation and the custom validation to one cell F2. So users can choose either the options given, or choose other and input the data they want, but the format must be ABC xxxx.
Any suggestions and helps are appreciated. Thanks in advance

Thanks #pnuts & # YowE3K, with the reference from here. I had successfully achieve what I want.
Solution: Right Click F2 -> Format cells -> Custom -> Type "ABC "#

Related

How can using user defined function in custom data validation?

In my Worksheet I have a Table and want to define Data validation for a column that contained the date, as bellow:
=S2M(B2)<>"Error"
In above, S2M() is a user defined function for converting date from Persian date to Gregorian date, because checking input date is right.
But excel is not letting me use user defined functions in Custom Data validation.
This error shows: A named range you specified cannot be found.
Please note that I was using bellow code in Custom Data validation and that works, right.
=AND(LEN(B2)=10;ISNUMBER(IFERROR(VALUE(MATCH(VALUE(MID(B2;1;4));INDIRECT("intTable[Year]");0)&MATCH(MID(B2;6;2);INDIRECT("intTable[Mounth]");0)&MATCH(MID(B2;9;2);INDIRECT("intTable[Day]");0));FALSE)))
Explain is a Persian date example: 1396/05/25
Thanks.
You can do that. Select B2, or whichever cell in row 2 you want the validation to apply to. Now define a name called, say, IsValid, using:
=S2M(B2)<>"Error"
Now in the data validation box, all you need to enter is:
=IsValid
in the source box and make sure to uncheck the Ignore Blank option.

Freeze column content from drop down in Excel

Hi I am new to excel for this kinds requirements.
I want to freeze the cell content (from a drop down) once a selection is made. Users should not be able to modify the entered content. Once the selection is made from data validation list then user can not change it.
Ex. If we have "M" and "F" in drop down(Data validation). Once user select "M" then he will not allow to change this with other option.
Let me know if you need more clarification. Direct me to the answer if question is already there.
I would suggest having conditionals control your validation. For instance:
If your validated list containing 'M' & 'F' is in cell A1, place a condition in say cell A2:
=IF(OR(A1="M",A1="F"),A1,"M")
And then for A3:
=IF(A2=A1,A2,"F")
Then set your validation list to cells A2:A3. By doing this, the dropdown can start unpopulated, a user makes a selection, and then the cells guiding the validation change to the users selection. This is a decent option if you are not comfortable with VBA. Good luck!

Get the id of the selected value in a dropdown validation list on Excel in VBA

Using Excel, lets say I have a validation list made of 5 values like this one :
Patate
Tomate
Courgette
Concombre
Patate
In a cell containing a drop down list made of these 5 value, I select the fifth value : "Patate".
I want to get in VBA that this cell contains the 5th value of my validation list. Something like :
x = Cell.Validation.GetIDValueSelected
x = 5
I can't use Vertical search because I might have 2 or even more time the same value in my list (too long to explain why).
This list is also dynamics (depending of another sheets) so it doesn't always contains 5 values.
I hope I made it clear for everyone to understand my needs but I will be glad to add more information if needed.
Thank you for your time.
Sadly, once you have used DV to fill a cell with junk, there is no way to tell which piece of junk you picked:
You would have to pad each piece of junk with a different number of blanks.

Storing user inputs for retrieving later

I have a spreadsheet where the user inputs various details on an inputs page and then presses a calculate button to get what they want. The inputs are strings, numbers and dates.
I want to save the inputs for each calculation for the user so that at a later date they could enter the calc id and not have to renter the inputs.
One simple way I thought of doing this was to copy the inputs when the calculation is run to another sheet with the inputs in a column with the calc id. Then just save future inputs in a separate column and lookup the correct column to retrieve the inputs at a later date.
I read this question - What are the benefits of using Classes in VBA? and thought it would be good to make a class called CalculationInputs that had all the details stored in one object. This may be overkill for what I need but i wanted to ask how other people would solve this simple task.
You can use Names to define variables within the scope of a workbook or worksheet. Typically these are used to define ranges, and more specifically dynamic ranges, but they can also be used to store static/constant values.
To create a Name manually, from the Formula ribbon, Names Manager:
Click on the "New" button, and then give it a meaningful name:
Make sure you put ="" in the "Refers To" field, if you leave it blank, the name will not be created.
Then when you press OK, or any time you go to the Names manager, you will see a list of all available Names in the workbook.
You can edit these through the Names manager, which is probably tedious, or you can easily use VBA and inputs to control them, for example:
Sub Test()
ActiveWorkbook.Names("MyAddress").RefersTo = "734 Evergreen Terrace"
End Sub
You could do something like this to capture the value, our use other macros or user firm code to assign the value to the Name.
Activeworkbook.Names("MyAddress").RefersTo = _
Application.Inputbox("please enter your address")
Etc.
If you run this, and then review the Names manager, you'll see the value has been updated:
In VBE, you can refer to the name like:
Debug.Print ActiveWorkbook.Names("MyAddress").Value '# Prints in the immediate pane
Range("A1") = ActiveWorkbook.Names("MyAddress").Value
These can also be accessed (read) from the worksheet, like:

Show Cell Range on UserForm; then update

I've been using a crude method to help the user update some cells - by having them in a sheet. Is there any way I can display the various ranges in a userform, one by one, then have the user update them, click a button and move onto the next one?
Essentially, can I have Excel automatically generate an input form based on a range? The process of updating and saving back to the sheet I can do; it's the production of the correct form that I can't.
It's possible to do this, but the only way I can think of is to make a userform that automatically populates itself based on a range passed in. This way you could have different macros in Excel that call the form to populate based on different ranges. I built a proof of concept Excel file for trying this, and it seems to work, the only issue I can think of being that you need to figure out a way to tell the user what input field is what.
I think what needs to be done is to add controls programmatically to a userform (I name the textboxes as the cell address it's going to populate) then when the form is closed loop through all the textboxes and populate the cells with the textbox values.
You can see what I did at:
https://my.syncplicity.com/share/uicgbs3rl0/InputForm.xls
I think all that would need to be done is for you to work out how to add labels for the textboxes, and make sure the form is resized based on the controls you add...
I am not quite shure what you are looking for, but you could insert a second sheet and use it as a "form". An other way could be a dialog box with an input field.
Either way, you present the cells you want the user to change one by one, using a vba-function. You implement a "previous field" and a "next field" button, so the user can step through the range of cells. If the user hits "next field", you save his input and take the next cell from a previous defined range of cells.
You could have a "config field" in which you define the range of cells you want to change.
This is pretty rough and old-fashioned but if you have the data in standard list format - i.e. column headers in the first row of your range and then one record of data in each row below - then selecting a cell within the range and going Data > Form will give you a crude input form with roughly the functionality you need.
You can also do this in VBA by calling the ShowDataForm method of the appropriate worksheet. Just select a cell within whichever range you need first. The macro will remain paused until the user closes the data form