How to extract string value based on delimiters - excel

I need help with an Excel formula to extract a value from a string, based on delimiters.
This is the string I would like to extract the first 10 fields from: ES_ABC_FACEBOOK_SocialImage_FACEBOOK_Reach(CPM)_DEM_18-45_Apr19_abc_def_ghi
In other words, I would need to get ES_ABC_FACEBOOK_SocialImage_FACEBOOK_Reach(CPM)_DEM_18-45_Apr19_abc
Bearing in mind that the number of fields (separated by delimiters) may vary in the dataset but that I need to consistently only pick up the first 10 fields and drop however many fields are succeeding the 10th field.
Thanks in advance!
Robin

You could try this:
=LEFT(<your cell>,FIND("||",SUBSTITUTE(<your cell>,"_","||",10))-1)
e.g. =LEFT(A1,FIND("||",SUBSTITUTE(A1,"_","||",10))-1)
The formula finds the 10th underscore, and the gives you all the characters up to it (minus the underscore).
If you need to change how many fields it gives you back, change the 10. The -1 at the end just removes the final underscore. Of note, the || is just a simple set of characters I can't imagine will ever appear in your strings. If it does, something else will need to be selected.
Lastly, if some of your strings will have less than 10 fields, try:
=IF(ISERROR(FIND("||",SUBSTITUTE(<your cell>,"_","||",10))-1),<your cell>,LEFT(<your cell>,FIND("||",SUBSTITUTE(<your cell>,"_","||",10))-1))
This gives you the whole string in the event that there are less than 10 fields.
Hope that helps.

Related

How to Automatically add thousand separators for every number in a string?

How can i create a thousand separator for every number which is in my string?
So for example this string:
string = "123456,78+1234"
should be displayed as:
TextView = "123.456,78+1.234"
And the string should be editable, so the thousand separator should adapt when i remove or add a digit.
I have already read all the posts I could find about it, but I could never find an up-to-date working answer. So I would be really grateful for your help!
Your question contains two sub-questions:
A. You want to add thousand separators to a string which contains a group of numbers.
B. You want it to change.
And the answers are:
A: In your example there's , as a delimiter, so you need to split the string using this delimiter to an array of strings.
Then iterate over them and have your dots added to every 3nth index of their characters; you can also use String.format("%,d", substr.toLong()).
Lastly, append all of the strings back together with , as the separator.
B: This one can be done in different ways. You may store the original string somewhere and observe it, so when it changes it goes to the function which does A, and use the function result the way you like (which I suppose is to be set in a TextView).

Removing first two digits in Excel if the character length is greater than certain number

I have cell phone numbers in Excel some with country code- 91 and some without country code. I need to remove the country code. We have 10 digit phone numbers so I need to remove the first two digits if the character length of the cell is greater than 10, i.e. if I have a number with country code like 917465785236 I need to remove the first two digits- 91 so that I only have 7465785236. I am trying the below piece but it doesn't check the IF condition and removes the first two digits from all the cells. Can someone tell me what's wrong I am doing here:
=IF((LEN(A1>10)),RIGHT(A1, LEN(A1)-2))
You probably need to put the parentheses differently for the Len function:
=IF((LEN(A1)>10),RIGHT(A1, LEN(A1)-2))
You're not using the parenthesis properly. Also since you strictly want to have 10 characters, you don't need to calculated the length in the RIGHT formula.. It needs to be like this:
=IF(LEN(A1)>10,RIGHT(A1, LEN(A1)-2),A1)
Now, that is the issue with your formula, but the solution to your question doesn't even need a IF statement, You can simply use:\
RIGHT(A1,10)
It will automatically get the 10 characters at the end and remove the rest.

Extracting certain numbers from a cell containing numbers and special characters

I have cells that contain both numbers and special characters such as this:
[1:250:10]
The 'coordinates' shown above can be in the following format.
[(1-9):(1-499):(1-15)] in terms of what numbers can be within each part.
How do I extract these three numbers into three separate cells?
Assuming your data is in Cell A1 the to extract first number use following formula
=MID(A1,2,(FIND(":",A1,1)-2))
for second number use
=SUBSTITUTE(MID(SUBSTITUTE(":" & A1&REPT(" ",6),":",REPT(":",255)),2*255,255),":","")
finally for third number enter
=SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(A1,":",REPT(" ",LEN(A1))),LEN(A1))),"]","")
Just tossing out some other options.
First number since it only has a length of 1 digit and is on the left side, use the following:
=RIGHT(LEFT(A1,2))
second number will be found by locating the : in the string
=MID(A1,FIND(":",A1)+1,FIND(":",A1,FIND(":",A1)+1)-(FIND(":",A1)+1))
third number will be dealt with in the same way as the second but we will use the second : and the ] as the identifiers as to where to grab from and how much to pull.
=MID(A1,FIND(":",A1,FIND(":",A1)+1)+1,FIND("]",A1)-(FIND(":",A1,FIND(":",A1)+1)+1))
now all those number will actually come through as text. If you want to have them as numbers in the cells, send them through a math operation that will not change their value. Do something like +0, -0, or *1 at the end. Alternatively you could add -- at the start of each formula (yes that is double - incase you were wondering if it was a typo)

custom data validation in Excel for alpha-numeric-alpha value

I want to force users to enter data in a specific cell in a sequence like ABCDE1234F
i.e. first five characters must me letters then four digits and last must be a letter using custom data validation.
It is quite long:
=AND(ISNUMBER(SUMPRODUCT(SEARCH("~"&MID(A1,ROW($1:$5),1),"abcdefghijklmnopqrstuvwxyz"))),ISNUMBER(SUMPRODUCT(SEARCH("~"&MID(A1,ROW($6:$9),1),"0123456789"))),ISNUMBER(SUMPRODUCT(SEARCH("~"&MID(A1,10,1),"abcdefghijklmnopqrstuvwxyz"))),LEN(A1)=10)
It goes through each of the required text characters and checks if it is a number or a string. Then it test the full range of numbers for text. It also ensures that it is ten characters long.
You may try following formula
=AND(ISTEXT(LEFT(A1,5)),ISNUMBER(MID(A1,6,4)*1),ISTEXT(MID(A1,10,1)),IF(LEN(A1)=10,TRUE,FALSE))

Concatenate Custom Function

On a daily basis I need to load data to one of our systems. However Excel deletes the previous zeros in front of the contractor IDs. So i have to add THREE zeros manually. I normally use the CONCATENATE function however now the IDs are coming differently so some IDs now only need to have TWO zeros added.
example:
ID
911111
I use concatenate to make it look like:
000911111
I came up with the IF formula that detects if the ID starts with a number NINE, to concatenate TWO zeros and if not, then to add THREE zeros.
example:
=IF(LEFT(A32,1)="9",CONCATENATE("00",A32),CONCATENATE("000",A32))
Now I want to create this formula as a custom defined so I do not have to write down the formula ever time I work on the data every day.
Any suggestions I will really appreciate.
In addition to the formatting responses provided in the comments, you could use the RIGHT function to cut off the leading zeroes to the appropriate amount.
For example, assuming A1 holds a string of numbers, between 0 & 9 digits long. We can create text representing a 9 digit string, with as many leading zeroes as necessary, as follows:
=RIGHT(REPT("0",9) & A1,9)
REPT("0",9) tells Excel to repeat the character "0" 9 times. It then tacks on whatever text is in A1. Then it takes only the rightmost 9 characters of the concatenation.
I generally would recommend the Formatting options noted in those comments, unless you need the text to be 9 characters for other formula purposes.

Resources