I have a data validation issue.
My cell reference should be 2 letters then 4 digits then 1 letter
As Example - AB1234A, xY0123z
Need to consider Both simple and Capital as well. Other way of input need to reject.
Use custom validation formula for that cell.
Check if first 2 are letters with ISTEXT and LEFT formulas. If 3rd, 4th, 5th and 5th are numbers with ISNUMBER and MID formulas, check if length is 7 symbols with LEN and so on. Wrap everything with AND
And you will get something like this:
=AND(LEN(C4)=7,ISTEXT(LEFT(C4,2)),ISNUMBER(VALUE(MID(C4,3,4))),ISNUMBER(RIGHT(C4,1)+1)=FALSE)
(Note that if you extract 1 symbol with LEFT, RIGHT or MIDand it is a number it will be treated like text. Workaround is to add any number and check if it converts to a number (adding number to actual text would give value error)
Related
I have a document in google sheets and the column consists of the name and version, like NLog.Config.4.3.0, NLog.Config.4.4.9 and so on.
See the image below for other examples.
I need to divide this into two columns - name and version, but I'm not familiar with regular expressions so close that I can get this info.
I can use excel and then import it to the Google doc, it doesn't matter for me how to do that.
enter image description here
You can try something like this:
Suppose you have your string in A1, then in B1 you can enter this:
=LEFT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")))
and in C1 this:
=RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)
you may need to do some adjustments if there are cases without numbers as it will produce an error, for example you can round it with an Iferror like this:
=IFERROR(LEFT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))),A1)
Note: A1&"0123456789" is a 'trick' to avoid the search to return error, as the search is looking for all the numbers in the array; we just need the position of the first one, thus the MIN().
Supposing that your raw data were in A2:A, place this in B2:
=ArrayFormula(IFERROR(REGEXEXTRACT(A2:A,"(\D+)\.(.+)"),A2:A))
The regular expression reads "Extract any number of non-digits up to but not including a period as group one, and everything remaining into group two." (In other words, "As soon as you run into a digit after a period, start group two.")
The IFERROR clause means, "If this pattern can't be found, just return the original cell data."
Assuming your content is in column A (Google Sheets), try this arrayformula in any cell other than column A:
=arrayformula(iferror(split(REGEXREPLACE($A:$A,"(\.)(\d+.+$)",char(6655)&"$2"),char(6655)),))
There are two regex groups denoted in ():
(\.) and (\d+.+$).
The first group looks for a dot . - it's escaped using \. The second group looks for a number (0-9) \d, one or more occurrences + then ending with $ one or more + of any character ..
The replacement is char(6655) (wouldn't usually be found in your dataset), and the contents of group two $2.
Then the split function divides the text into two columns by the char(6655) character.
iferror returns nothing if nothing is split.
The arrayformula works down the sheet.
I have some data in Col"K" where from i am just trying to get the left characters as i tried in Col"H" using formula.
But what i used is Left function like =Function(cell,10) that is not the correct way characters can be more than 10 or less than 10.
1st formula should be dynamic to get the left numeric values.
2nd Formula should copy and paste the same numeric values until next value comes as available in Col"I"
I tried to make it but what i can do is to create left function and do not know how to develop it dynamic.
Any help will be appreciated.
Sheet Link
https://docs.google.com/spreadsheets/d/1nJZeWDZ0EWgmWB0z17xU93fjIOFsu46EL37IJqJzZ_0/edit?usp=sharing
This formula should do the job.
[J2] =IFERROR(TRIM(LEFT(L2,FIND("-",L2)-1)),J1)
Note that it will fail if placed in row 1 and there is no dash in L1.
Use find function to get numeric characters length.
=iferror(trim(left(L3,FIND("-",L3)-1)),M2)
Here we are finding the separator "-" in your text and it gives us index number of separator.
Then picking text from start to before index number i.e., Numeric value and removing blank spaces, if any, using trim function. If we don't have number/separator in the text then showing previous cell value using iferror function. So, Make sure first row always has numeric value.
Same has implemented in the sheet you have shared
As per the latest data I have updated my answer as below , now it is checking output is numeric or not:
=IF(COUNT(FIND({0,1,2,3,4,5,6,7,8,9},J9))=0,K8,TRIM(LEFT(J9,FIND("-",J9)-1)))
I used =IF(A2=A1,C1&","&B2,B2) to concatenate a string of associated SKUs across multiple rows into one cell. The problem is some of the SKUs start with 0, and this got removed with the formula. (Also, some of the rows are showing up as error cells with the red text and fill. The error message says they are a number being stored as text. But it's not like that with every one, and I don't know why.)
All the SKUs have 8 digits, so the incorrect ones will have 7 digits. For example:
Looks like: 4286000,4286800,4310001,4310801,14872001,14872801,14877001,14877801
Should be: 04286000,04286800,04310001,04310801,14872001,14872801,14877001,14877801
I tried the =TEXT function, and got a funny (wrong) result. For example, in a string where all six SKUs need a leading zero, I added 48 zeros in the format_text section of the function, with commas after every 8 zeros. It put the commas in every three digits, basically outputting as a large single number.
Is this something that can be solved with formulas, or does it require VBA?
Similar to tigeravatar's comment which will return a string instead of a number but will have the lead zero:
=RIGHT("00000000"&B2,8)
or
=RIGHT("00000000"&MAX(len(B2),8))
Basically it adds 8 zeros to the front then takes the last 8 characters. Or in the case of the second formula it will take a minimum of 8 characters and a maximum of the length of what is already in the cell. If you know you only have a minimum of 7 characters, then you could just add 1 zero.
Alternatively you could add the zeros using a REPT function:
=REPT("0",MAX(8-LEN(B2),0))&B2
The max is in there in case you have a number longer which would wind up with a negative value for REPT. In that case, MAX would return 0 instead avoiding the error with REPT. The result of this formula is also a string.
If you want to see a leading zero, but keep the cell value as a number, then you would need to apply custom formatting to the cell. Just remember though the zero is not really there if you go that route, the cell is just displaying things as 8 digits long.
You could just change the cell formatting to a custom 00000000 if it's a visual thing.
I have an Excel sheet, there are 500 cells with only data in column E. How do I check the cell does not have any numbers in a sequential order like 12345 or 54321 for example. Each cell has a 5 digit long number.
Here's a formula:
=OR(AND(MID(A4,{1,2,3,4},1)+0=MID(A4,{2,3,4,5},1)-1),AND(MID(A4,{1,2,3,4},1)+0=MID(A4,{2,3,4,5},1)+1))
It checks the first four digits one-at-a-time against the last four digits, to see if all are either one more, or one less. That's where the +1 and -1 parts come in. The +0 parts just force the strings yielded by the MID function to be numbers.
It uses arrays but doesn't need to be array-entered.
=IF(AND(ABS(MID($B1,1,1)-MID($B1,2,1))=1,MID($B1,1,1)<MID($B1,2,1)),1,0)+IF(AND(ABS(MID($B1,2,1)-MID($B1,3,1))=1,MID($B1,2,1)<MID($B1,3,1)),1,0)+IF(AND(ABS(MID($B1,3,1)-MID($B1,4,1))=1,MID($B1,3,1)<MID($B1,4,1)),1,0)+IF(AND(ABS(MID($B1,4,1)-MID($B1,5,1))=1,MID($B1,4,1)<MID($B1,5,1)),1,0)
( A late option )
I have around 30 numbers which are either 1, 2 or 3 digits which are codes. These codes are attached in front of other numbers. I want to know what code is in front of a number, for example for the number 35467036 the first two digits matches with the code 35. So I want the output for that to be 1.5.
This is my current setup, I have a table with all the codes followed by the output in the next column. If all the codes were three digits long I could just do this =VLOOKUP((LEFT(E6,3)&"*"),D1:E3,2,FALSE) but they are unfortunately not.
I have also tried using nested IF statements but I can only go so far as 7 levels.
Will this only be possible in VBS or is there anther way?
Edit:
The code column is formatted to text. If I enter the value 3 into LEFT it does not work for two digits. Is there anyway I can make it work for 1, 2 and 3 digit codes? Also the codes do not overlap, for example, there isn't going to be 96 and 965 in the code table.
Seven nested IFs as a limit points to a very old version of Excel. You may want to consider upgrading to a version that is still supported in this millennium.
But your main problem is that the data type of your lookup value is text, because you concatenate a string with a wildcard. Whereas your Lookup Table's first column is probably made up of numbers.
In order to solve this you will need to add a Text column to your lookup table that represents the numeric value as a text value.
IF you want to use Vlookup, that helper column will need to be the first column of your lookup range.
You can use an Index/Match instead of Vlookup to be independent of the column order, as this screenshot shows:
Column H shows the formula that has been applied in column G.
Edit:
According to the screenshot you posted, you want to look up from the table in columns E to F and this table only has the short codes. Therefore, it makes no sense to add a wildcard to the lookup value. You just need to extract the value you want to use for the lookup.
If you want to lookup only two digits, then you need to extract only two digits. Adding a wildcard does nothing to remove the third digit.
In the screenshot below, a helper column feeds the LEFT() function the number of characters to extract, then uses that value in the VLookup.
=VLOOKUP(LEFT(A1,B1),$E$1:$F$5,2,FALSE)
=INDEX($G$2:$G$5,
SMALL(
IF(LEFT(A1,3)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,2)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,1)*1=$F$2:$F$5,ROW($G$2:$G$5)-1))),1))
=INDEX(LookupValues,Small(ArrayOfRowsFromIfStatements,FirstRow))
This is an array formula so you will need to use Ctrl+Shift+Enter while still in the formula bar.
We use If to build an array of Row numbers where the conditions match or return FALSE if not. The Small function then returns the smallest result in the array which will be the first row where conditions match.
We then index the results returning that row number (-1 deducted from rows to offset the headers).
If your numbers in column A are always 6 digits + the code length you can use this:
=VLOOKUP(--LEFT(A1,LEN(A1)-6),E2:F5,2,FALSE)