Sort issue with delimiter in excel - excel

I have a column of data in excel that contains cells of just numbers and then cells of two numbers with a delimiter in between. I want to sort by this field but when I do so it puts all the fields with delimiters down at the bottom. I would like them to be sorted by the first number thats before the delimiter. Would there be an easy to do this using sort or another built in feature?
Regular Cell:
123456
Delimited Cell:
123456 | 789012

you could add one additional column and then split delimited cells and sort the new column.
This would be the easiest i guess

Rather than one, big function, let me show you how to split out the first number before the delimiter.
Let's say A1 is 123456 | 789012.
In B1, put the formula =FIND("|",A1). This will be the index of the delimiter, 8, or a #VALUE error if no delimiter is found.
In C1, put the formula =ISERROR(B1). This returns a TRUE if it finds the delimiter, or else a FALSE.
In D1, put the formula =IF(NOT(C1),LEFT(A1,B1-1),""). This returns the string before the delimiter, 123456, including a trailing blank. You may sort on this as a string, if all the numbers have the same number of digits. (Note that string 21 is lexically higher than string 123456.)
If you need to sort the numbers a numbers, then in E1, put the formula =VALUE(D1). Now 21 < 123456.

Related

Removing 1st character of number before checking if its > 0, combined with indirect function

I would like to use the =indirect() and =value() function together. I am to count how many numbers are > 0 in another sheet, in the rows I:I. In these sheets, the numbers are not formatted as values, and I am not to do this manually.
In addition, for the numbers, they are formatted as
" 123 "
With a space before the number.
I also need to remove the space in front the numbers in order for this to work.
In my current sheet, in cell J1, I have written "I:I". In the cell A3, I have the name of the sheet that I would like to count the numbers from.
My attempt so far:
{=COUNT.IF(INDIRECT("'"&A3&"'!"&$J$1);">0")
However, this just returns values 0. This is because there is a space infront of the numbers. How do I remove this space? I need to implement it in this function
I've edited the post a bit, as I noticed there was a space infront of the numbers
On a worksheet, if your value " 123 " is in cell A1 then you could use a formula like:
=VALUE(TRIM(A1))
...to TRIM the spaces, and convert the string to a numeric VALUE.
Or, in VBA, something like:
myValue = CInt(Trim(myString))
...to Trim the spaces, and Convert to CInt-eger.
Or, in many ad-hoc situations it's easiest to use "Text to Columns" to remove padded spaces (or any other character, really).
More ways to convert text to numbers here and here.
More ways to remove unneeded spaces here and here.

match the number from comma separated value and count

I have a comma separated value in A2 and same numbers in different cells B1, C1, D1.... I want to match them from comma separated value and find out the count in B2, C2, D2. Please see the image attached you will get the context.
Can we achieve this by formula or macro in excel?
Tried formula:
=LEN(TRIM($A$2))-LEN(SUBSTITUTE(TRIM($A$2),C1,","""))
Also, I have two data sets where I will be using this formula to find out the count of number from comma-separated value and based on count I want the repeated ones to come in a different cell please refer the image for better understanding.
Probably not the best solution but get the job done. Please note it is case-sensitive and please make sure to press Ctrl+Shift+Enter upon finishing this formula.
{=SUM(--(EXACT("!"&TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",100)),(ROW(INDIRECT("1:"&LEN($A2)))-1)*100+1,100)),"!"&B1)))}
You can replace ! in the above formula with a unique symbol that will never appear in the text string to be safer.
The logic is to SUBSTITUTE the comma , with and long string of blanks, then use MID to find each value in the text string and return the result as an array, then use EXACT to match each value in the array with the look up value and return a new array of TRUE and FALSE, then SUM up all TRUE which will give the count of the look up value.
UPDATE #2
As requested by OP, here is one way of solving the second query which is to match the same value with the same occurrence from two text strings separated by comma ,.
The formula in Cell C2 is from the original solution which is used to find the occurrence of a given value in a text string;
The formula for Range C6:K6 is an array formula as shown below. I used a helper row to layout the matching values, and excluding the one that has 0 count for both data set;
{=IFERROR(INDEX($C$1:$K$1,,AGGREGATE(15,7,COLUMN(INDIRECT("1:"&COLUMNS($C$1:$K$1)))/($C$2:$K$2=$C$3:$K$3)/($C$2:$K$2>0),COLUMN()-2))&",","")}
The formula in Cell L8 is concatenating all values from Range C6:K6 and remove the last comma , from the final text string:
=LEFT(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6),LEN(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6))-1)
The following worked for me, give it a try:
Formula in B2:
=(LEN(","&SUBSTITUTE($A$2,",",",,")&",")-LEN(SUBSTITUTE(","&SUBSTITUTE($A$2,",",",,")&",",","&B$1&",","")))/LEN(","&B$1&",")
Drag right...
A simpler way of doing it is to simply calculate the difference in the length of the string minus the length of the string when replacing the value searched by nothing and dividing by the length of the string searched
The formula would be:
=(LEN($A$1)+1-LEN(SUBSTITUTE($A$1&",",B1&",","")))/LEN(B1&",")
There is a much simpler solution:
=COUNTIF(SPLIT($A$2, ","), B1)

Extract two numbers out of a string in Excel

I have a string that I need two numbers extracted and separated into two columns like this.
ID:1234567 RXN:89012345
ID:12345 RXN:678901
Column 1 Column 2
1234567 89012345
12345 678901
The numbers can be varying number of characters. I was able to get column 2 number by using the following function:
=RIGHT(G3,FIND("RXN:",G3)-5)
However, I'm having a hard time getting the ID number separated.
Also, I need this to be a function as I will be using a macro to use over many spreadsheets.
A way to do this is:
Select all your data - assuming it is in a string all the time - which means one cell has one row with ID&RXN nos. So if you have 100 rows such data, select all of it
Go to the Data tab, Text to columns
Choose Delimited>>Next>> choose Space here, in Other, type a colon(:) >> Finish
You will get "ID" in first column, every cell; ID no in second column every cell; RXN in third column every cell and RXN no in 4th column every cell.
Delete unwanted columns
With data in column A, in B1 enter:
=MID(A1,FIND("ID:",A1)+LEN("ID:"),FIND(" ",A1,FIND("ID:",A1)+LEN("ID:"))-FIND("ID:",A1)-LEN("ID:"))
and copy down. In C1 enter:
=MID(A1,FIND("RXN:",A1)+LEN("RXN:"),9999)
and copy down:
The column B formulas are a pretty standard way to capture a sub-string encapsulated by two other sub-strings.
If your format is always as you show it,then:
B1: =TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1," ",REPT(" ",99)),":",REPT(" ",99)),99,99))
C1: =TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1," ",REPT(" ",99)),":",REPT(" ",99)),3*99,99))
We substitute a long string of spaces for the space and : in the original string. Then we extract the 2nd and 4th items and trim off the extra spaces.

Count Numerical Values Separated by Comma

Is there a formula to count the number of numerical values that are separated by a comma in a single cell?
http://support.microsoft.com/en-us/kb/187667
Assuming string in A1:A1... but you can alter to just be a cell or a range...
=SUM(LEN(A1:A1)-LEN(SUBSTITUTE(A1:A1,",","")))/LEN(",")+1
This can be done easily by searching the finding the number of commas in the cell and adding 1.
If the cell you want to search is A1 then use this:
=LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1

I want to delete first characters in a cell?

I want to delete first characters in a cell and show it in another cell.
I have A1 - 1900: (1873, 'asd#asd.com
I want to show B1 - asd#asd.com
You can use the RIGHT function to 'keep' a number of characters:
=RIGHT(A1, LEN(A1)-B1)
Will chop off B1 characters of the content of cell A1 (in this case, B1 should contain 14, but you can make it a calculation, too)
If you have always a quote before your email, just select you column, go to Data / convert and use "'" as separator
If the apostrophe precede every e-mail address then this formula can be used in column B.
=MID(A1,FIND("'",A1)+1,LEN(A1))
The find function returns the first occurrence of the apostrophe.
The Mid function extracts the text after the apostrophe.

Resources