I want to apply data validation to reference numbers, to force the following layout (ideally uppercase only):
XX_NNX-XX_NNN_NN-XXX
X = Numbers
N = Letters
Ex: 12_AB1-23_ABC_AB-123
The following custom formula allows all of it except for numbers - is there any workaround for this?
I don't want to use * since it allows for more characters than I want.
=COUNTIF(A1,"??_???-??_???_??-???")
You can choose AND to add a condition to the function you have already written. e.g. following shall test the positions which shall be numeric.
=AND(COUNTIF(A1,"??_???-??_???_??-???"),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0))
Notes: This is fairly basic approach and may need some tweaks if you have cases involving usage of decimals etc.
Edit: You can try below approach for checking upper case text in specified positions.
=AND(COUNTIF(A1,"??_???-??_???_??-???"),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0),INDEX(FREQUENCY(-CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),{-91,-65,0}),2)=7)
Edit2: This turned out to be tougher than I had imagined. Following formula works in DV for cell A1.
=AND(COUNTIF(A1,"??_???-??_???_??-???"),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0),MIN(FLOOR(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),65))=65,MAX(CEILING(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),90))=90)
But due to some quirk, Excel won't let me simply paste it. So I wrote a small code for the same which applies DV to cell A1 and surprisingly it accepts that same long formula through code. Make sure that you delete DV in the cell before you run this code.
With Range("A1")
.Value = "12_AB1-23_ADC_AZ-123"
.Validation.Add xlValidateCustom, , , "=AND(COUNTIF(A1,""??_???-??_???_??-???""),ISNUMBER((LEFT(A1,2)&MID(A1,6,1)&MID(A1,8,2)&RIGHT(A1,3))+0),MIN(FLOOR(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),65))=65,MAX(CEILING(CODE(MID(MID(A1,4,2)&MID(A1,11,3)&MID(A1,15,2),ROW($A$1:$A$7),1)),90))=90)"
End With
Once in there, you can get it in any other cell by simply doing copy >> Paste Special >> Validation.
For clarity, I use Excel 2016.
Related
I find myself amazed by the magic of Excel non-transparent automatization. I have office 365.
I have the setup below, column P contains "Current value" that is taken into consideration for reports and column Q (Current formula) actually contains formulas that can be restored to P by removing the #.
Let's take cell P58 as an example:
If I write in P58 the formula =RIGHT([#[Current formula]],len([#[Current formula]])-1) and hit enter, Excel automatically converts it to =365.25/12/7 and sometimes converts it directly to the result of that function 4.35. Yes I said sometimes because I have not figured out the pattern.
I would expect after adding the =Right( formula that I would need to Copy - Paste special Values, and then replace = with = in order for Excel to recognize it as a formula.
The problem is this only happens for one file, my coleague has not been able to replicate it on other files.
I don't have any VBA triggers on Sheet or ThisWorkbook
How can I controll these actions that Excel does?
Oh and by the way, I have Fill formulas in tables to create calculated columns OFF:
Let me know if I need to upload a Demo video, I'm not sure how I would do that on stackoverflow at the moment.
I'm attempting to use the IFS, ISNUMBER, SEARCH, LEFT Excel formulas together in order to evaluate if a cell contains a specific designation in the first two characters of the text string in a specific cell and then output a specific text string into a different cell.
I have tried using various functions to accomplish this and my current code iteration seems close to working but it currently searches the entire cell (seemingly) ignoring my LEFT("14",2) argument.
The code 'works' as is but it will also 'work' if there is "14" anywhere in the cell, not just the first two characters of the cell. I have attempted to use the LEFT() function to evaluate the first 2 characters in the cell and then if TRUE it would output the "OUTPUT TEXT" but no success thus far.
I am new to nesting formulas in Excel so would appreciate insight as to why my code below isn't working as I intended. If there's a more streamlined way to accomplish this (without using VBA due to security restrictions) I am keen to learn... there's typically a more elegant solution to most things! Thank you for taking a look.
CODE:
=IFS(ISNUMBER(SEARCH("ABC",B21)),"Section One",(ISNUMBER(SEARCH("DEF",B21))),"Section Two",ISNUMBER(SEARCH("GHI",B21)),"Section Three",ISNUMBER((SEARCH(LEFT("14",2),B21))),"OUTPUT TEXT",TRUE,"MANUAL CHECK")
The cell B21 refers to where the text would be input in this format "14ABC1234".
PROBLEM:
Input of "14ABC1234" resolves as TRUE (as intended) but "10ABC1423" is also picked up as TRUE even with SEARCH(LEFT("14",2),B21).
Sidenote: I've also used IFS and ISNUMBER(SEARCH()) to evaluate if 'ABC'/'DEF'/'GHI' etc are within the cell and this has been working as intended.
I need to set data validation on an excel cell to be a specific format. I haven't been able to figure it out myself so far.
The requirements are:
20 characters in length
first 4 characters have to be numeric
characters 5&6 have to be '00'
characters 7-18 need to be alphanumeric
characters 19&20 need to be numeric
Can anyone help me with this?
Use a custom formula like:
=and(Len(A1)=20,isnumber(left(A1,4)+0),mid(A1,5,2)="00",isnumber(right(A1,2)+0))
and make sure to uncheck the Ignore blank option.
Note: this would actually allow any characters for 7-18. If it has to be restricted to A-Z and 0-9 that will require an addition to the formula.
Edit:
Based on the clarified requirements, I would suggest VBA be involved. Add a new module with this function:
Function IsValid(InputText As String) As Boolean
IsValid = UCase$(InputText) Like "####00[A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]##"
End Function
Then select the first cell to which you want to apply the data validation - I'll assume A1. Using Name Manager, define a name called IsValidEntry using the formula:
=IsValid(A1)
If your DV cell is not A1, use the appropriate address here but do not include any $ signs.
Now in the DV settings you can choose Custom, uncheck the Ignore Blanks option, and use =IsValidEntry as the source.
I am using Excel to calculate a string value where Evaluate() works fine but I am not allowed to use evaluate() in the Name Manager and I am not allowed to use it in VB A because the file gets converted to .xls. Here is the issue.
I have 100 s of a long formula example:
($F$10+0)+($F$11+0.125)+($F$10+0.0625)
which i need to evaluate the values between the brackets separately.
I am able to separate the formula to
A1 is ($F$10+0)
A2 is ($F$11+0.125)
A3 is ($F$10+0.0625)
I would like to put an "=" sign in front of this string and calculate the values of A1, A2, and A3.
However I am not allowed to use function EVALUATE() in the File Manager, it does not work in the cells and I am not allowed to use VB A to code the formula.
is there any replacement for evaluate that I can use?
thanks
Welcome to the dark side of Excel.
If you cannot use:
1) VBA
2) Macros
3) Evaluate()
4) File Manager / Define Name
Then there are no simple formulas that can help you (plus you can't make your own). Microsoft has purposely not addressed this issue for many many years.
So you are left to your own devices to create your own parser in Excel cells.
This can be very difficult if you have varying types of formulas that can change signs, or amount of addressed cells, or any number of other craziness that formulas can take.
However... if you have a minimum number of deviations for how the formula is expressed... you can write something that will do the trick.
This comes with a caveat... the formula must be provided with the same parameters each time. And what you gave as examples, has the structure defined exactly the same for each formula.
So therefore, using your examples, you can write this code in column A2:
=INDIRECT(MID(A1,SEARCH("$",A1),SEARCH("+",A1)-SEARCH("$",A1)),TRUE)+MID(A1,SEARCH("+",A1)+1,LEN(A1)-SEARCH("+",A1)-1)
Then you can copy that code over to B2 and C2.
This will give you the correct math as if it was a formula.
The structural parameters that are needed for this to work are:
1) The cell address must always start with a dollar sign $
2) The cell address must be immediately followed by a plus sign +
3) Only a single addition is done as the formula
4) The operand after the plus sign must be numeric
5) The formula must end with a Parenthesis )
6) It can't hurt to begin with a Parenthesis either (
And since all of your formulas adhere to this structure... the formula I provided will work.
If you need to change item 3 to also allow for 'subtraction', then you are going to need to add if statements to the formula and it's going to become complicated very quickly. Impossible? No. But a huge mess? Yes.
Anyway, this should work with all of your restrictions that you have. That is... if your formulas don't deviate from the structure that has been provided. If you have different formula structures, you'd need to let us know about them... or better yet, write your own code.
Hope this helped. :)
I'm having trouble trying to figure out a way to have two columns, one to show the entire formula that can be editable and the second to actually perform the formula.
Ideally, I would like my sheet to be set up like this:
Formula | Value
=5+2 | 7
=3-2 | 1
I would like to be able to change the Formula column and have it automatically update the Value column.
I've tried using the GetFormula() function but I don't think that's what I want to do as I would end up in a circular reference based on what I want to do. The closest I've got is using a Right() function and Text in the formula column or a space and removing the space. However, I end up with the text and not the solved formula instead.
Using =RIGHT(A2, LEN(A2)-1)
Formula | Value
=5+2 | =5+2
I have also tried using =RIGHT(A2,LEN(A2)-1) but without the "=" and can't figure out how to convert the "5+2" into text that I can use to solve. I'm hoping to do this with a formula and without a macro/VBA.
Here is how to do it.
1
Open the Name Manager. Control-F3 from the worksheet, and then click the New button.
2
For the Name field in the dialog, enter EVALA. I just picked this name; it stands for "Evaluate A". But you can pick whatever name you like.
3
For the Refers to field, enter this
=EVALUATE($A1)
4
Click OK and then Close.
5
In B1 enter this formula:
=EVALA
That's it.
You can now use this formula on any row in the worksheet and it will evaluate whatever is in the column A cell of the row where you enter the formula.
You can make a user defined function easily enough with VBA, but if you don't regularly use VBA then an alternative method is to create a Name object. Name objects can access certain functions not typically available in a cell's formula. One of these functions is "Evaluate" which will evaluate a string as a mathematical expression. Here's a demonstration how to do this.
NOTE: Pay special attention to the use of $. Chances are you don't want any $ in your name definition since that will prevent it from behaving in a relative manner. Also, Sheet1! means that this will not work on another sheet.
Update I just want to give credit for this method to the following sources. This is pretty neat stuff, so for anyone interested give it a read. The last link in particular gives a neat example of creating a chart with no data points.
MSDN Evaluating Defined Names
The power of evaluate (ozgrid)
XL4 Macro Functions in Names - JKP
Evaluate and Indirect
More unique functionality of Defined Names
This is probably the best solution for the OP, since it asks to avoid using VBA; however, this method is somewhat limited. It requires manual set-up on every sheet to be used. Much preferable I think is to create a very simple UDF like this...
Function Eval(Expr As String)
Eval = Application.Evaluate(Expr)
End Function
This can be added to any accessible add-in, making it available to any instance of Excel. A little more set-up, but less maintenance.
Just put a single ' before the formula in your A column:
'=5+2 will show in your cell as "=5+2". Then in the B column, just do the formula as normal, =5+2.