I'm trying to extract sections of text from an Excel cell then put some of those parts together.
Using LEFT, MID, TRIM, SUBSTITUTE & REPT (mainly helped by contributions on this site), I've managed to split each section down (they are separated by dashes) into it's constituent parts.
I've managed to do the easy bit which is to add sections 2 and 3 together (separated by dashes) using =L2&"-"&M2&"-"&.
I want to add the last section but the problem I have is that some of the names have 5 sections, some 6 and some 7 so I need a formula that says something like "If cells 9 & 10 are empty, use cell 8, if cell 10 is empty use 9 and if neither 9 or 10 are empty, use 10".
I've had a go with IF and AND but keep getting error messages, mainly about too many arguments. Any help would be much appreciated, I still quite a newbie to formula writing.
Assuming sections 8,9 and 10 are in columns R:T, you could use:
=LOOKUP(2,1/(R2:T2<>""),R2:T2)
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'd like to create a unique ID based on the value of a string in a cell by assigning every character a value and then summing the values of the characters in the cell to get a number.
For example if A=1, B=2, C=3, D=4; the cell containing ABBCD would be 1+2+2+3+4, and the sum would end up being 12. So the value of that cell would be 12. What is the easiest way to do this in excel?
I am going to assume that this is not a solution of any kind, but if you are trying to simply assign the numbers to letters and sum them, it is not a particularly complicated issue. Hopefully, by my giving this answer and us discussing how it does or does not meet your needs, we can figure out what the best alternative will be. Here is a formula that assigns 1 to "A" 2 to "B" etc and sums them when they appear in a string. I do not know if it handles the other 16 characters that may be in the original strings, but hopefully it will.
=SUM(CODE(MID(UPPER(A1),ROW(INDIRECT("1:"&LEN(A1))),1))-64)
This is an array formula.
Since I am updating this, I might add that Scott Craner's comment offers a formula that is not an array formula which would make it less problematic.
modifications
The above was intended to be a half-thought-out straw man since there is nothing in it to avoid duplication of values and it really was not tested significantly. However, to make it a bit more forgiving and to treat spaces and other characters that might be part of the original code, I would make some changes.
I would start by first replacing SUM with SUMPRODUCT as so that this is not an array formula as Scott Craner suggested. The original formula treats all spaces as -32, but I think we probably would want to always increase the value rather than have some characters increase it and others decrease it. Hence, I am changing it to only adjust the ASCII code for letters of the alphabet.
What I am proposing below is that for the alphabet, we give them the values of 1 to 26 by subtracting 64 from their values. Then, for the non-alphabetic characters, I would suggest retaining their actual ASCII code.
This formula does that:
=SUMPRODUCT(CODE(MID(UPPER(A1),ROW(INDIRECT("1:"&LEN(A1))),1)))-SUMPRODUCT((CODE(MID(UPPER(A1),ROW(INDIRECT("1:"&LEN(A1))),1))<91)*(CODE(MID(UPPER(A1),ROW(INDIRECT("1:"&LEN(A1))),1))>64)*64)
What it does is it starts with the sum of all ASCII values and then subtracts 64 only for those characters which are from "A" to "Z" inclusive. (A is ASCII 65 and Z is ASCII 90.) Since the ASCII characters from 1 to 26 are generally control codes, this should not overlap any actual characters that may be encountered within the initial codes.
I am adding a picture of a chart with the old and new values based on this change.
I should note that I changed something that is not apparent in the sheet as part of this test. Visually, Line 6 and Line 9 are apparently identical, but they produce different values for both the old and new formulas. This is because Line 6 has four trailing spaces which affect both the old and new counts. I had considered using the TRIM function but that function not only removes trailing spaces, but also removes leading spaces and limits intermediate spaces to single spaces. If the trailing spaces do need to be removed without impacting the rest of the original code, it may make sense to create a Public Function in VBA to invoke its RTrim function.
Remember, there is no checking for duplicates.
My last comment above has me concerned because if you truly want unique values and you have a tremendous number of items, you will not necessarily be able to spot places where two things like "John Wayne" and "Wayne John" came up with the same code for dissimilar values. While I do not have a way to ensure the uniqueness of the codes given how we are assigning them, I thought I would add a way to at least be alerted to them. By becoming aware of these duplicate assignments, perhaps you can manually address them if they aren't numerous or very common.
I set up a spreadsheet using only the newer formula in Column B and I added a formula in Column C to identify rows where there is another row with the same numeric code but a different original code. Since upper and lower case are considered the same, this is fairly straightforward. The formula I used in Column C is:
=IF(COUNTIFS(B:B,"="&B1,A:A,"<>"&A1)>0,"Not Unique","")
This produced this third result:
Remember row 6 has 4 additional spaces at the end, so it numerically gets the same sum as Row 12 (where there are two spaces between each word). Also note that although Row 3 and Row 15 look different, they are considered the same code since it is only a difference of letter case. Not every cell with "Not Unique" will be a problem. For example Rows 1, 2, and 10 are all flagged, but Rows 1 and 10 appropriately match; it is just that they do not match Row 2.
I would like to ask for your help with the formulation of a formula in Excel in order to compare the total number of search results upon using different sets of separator characters.
As I have multiple columns with content, as in the example below, I thought it would be possible to Count the search results in some way and do this for each column separately ( I would actually prefer to treat each column separately).
A
1 L-516-S-221-S-223
2 H-140.STR3
3 ST0 XP 23-9
4 etc.......
Preferably, I would like to use a varying a set of separator characters in order to determine the impact on the number of search results based on this set of separator characters. Logically, with an increasing number of separators more results will be returned (depending on separators included in the cell values of course).
The set of characters that I would like to experiment with is: “-_ .,;: “
Hopefully this makes sense and someone is able to help me out. Thank you.
Kind regards,
P
In your example - on its own will detect all three instances but for an overview you might construct a grid (say B1:H1 of your separators, including a space rather than an empty cell) and ColumnA each column in turn (maybe via links) then a formula in B2 such as:
=--ISNUMBER(FIND(B$1,$A2))
copied across to ColumnH and down to suit.
Alternative formula (for different question):
=IF(LEN($A2)-LEN(SUBSTITUTE($A2,B$1,""))>0,LEN($A2)-LEN(SUBSTITUTE($A2,B$1,""))+1,0)
Assumes, for example, no trailing spaces and separators are always separated. Results are not necessarily cumulative.
I've found some tools that can do what I want, but despite trying various options I can't work out how to put them in my existing formula!
I'm trying to generate an invoice reference number, which would look like 'ABC000012' - with the first row being ABC000001 and increasing in number as each row is added. I can currently generate 'ABC1' and so on, but can't work out how to add the preceding 0s.
I'm currently using CONCATENATE as follows:
=IF(ISBLANK(B2),,CONCATENATE("ABC",(ROW(1:1))))
What do I need to add to this, and where, in order to get the references I'm looking for?
I'm also happy to be advised that I should change the whole formula if there's something different that will work better
Thanks
Use TEXT() to set the preceding 0:
=IF(ISBLANK(B2),"",CONCATENATE("ABC",TEXT(ROW(1:1),"000000")))
=IF(ISBLANK(B2),"","ABC"&RIGHT("000000"&ROW(1:1),6))
This is based off Scott Craner's answer. The difference is that is will limit the number of digits in your invoice to 6 characters. if you want it to always be 8 characters long change the 6 to an 8 and increase the number of 0 between the " ". Alternatively you could also do:
=IF(ISBLANK(B2),"","ABC"&RIGHT(rept(0,6)&ROW(1:1),6))
In the above formula to change the number of digits n the invoice number, you would need to change both 6's
Caveat:
If there is a blank cell in the middle of your list, that number will be skipped for each blank cell. To avoid this, you will need a different counting method than row(1:1).
I have a huge data set that I need to separate into a hierarchy. Currently the only way to tell which level the data point is in the hierarchy is how many spaces are before the first letter (It is from an Essbase pull). I need to separate it out into various columns so that I can see the structure more effectively. There are 7 different numbers of spaces (the separation between hierarchy levels). I honestly have no idea how to get this done. Does anyone have any thoughts or advice?
You can use this formula:
=IF(COLUMN(A:A)=FIND(LEFT(TRIM($A1),1),$A1),TRIM($A1),"")
Drag across and down.
If you do not want 15 - 40 spaces and it appears that all are multiples of 5 you can do this:
=IF(COLUMN(A:A)=INT(FIND(LEFT(TRIM($A1),1),$A1)/5),TRIM($A1),"")
Using the examples in column B:
Insert column A before data. Then, get length (len) before triming (trim) spaces and after (trim) and subtract. (This assumes no spaces at end however)
=LEN(B1)-LEN(TRIM(B1))
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.