Excel: sort column with mixed numbers and letters? - excel

I am working of the dataset in Excel that I obtained from an experiment. Since I needed some ratings (and I wanted the raters to be blind) I completely randomized the answers and now I can't put them back in order!
This is what I have:
1A
38R
22R
7A
41R
64A
etc...
And this is what I need in the end:
1A
2A
3A
...
99R
100R
101R
Thank you!

I have created two new columns (B and C in this case, as in the other example posted).
I have typed LEFT(A1,LEN(A1)-1) in column B to get the number; then =RIGHT(A1,1) in column C to get the letter; finally I can sort by B and C.

You will not get your desired output by sorting alphabetically, because 100R would come before 2A.
If your values will always be in the format of a number followed by a single character and will be at most 5 characters long, you can use #Scott Craner's formula =RIGHT("00000"&A1,5) to pad the left of your value with "0" so that you can alphabetize correctly. 100R will become 0100R. 2A will become 0002A. These will now alphabetize correctly.
Now you can simply sort your range by column B ascending alphabetically.
If you need more characters, just add as many zeroes as characters to the formula, and change the 5 in the formula to your new number of characters.
Here is an example excel file.
INPUT
+---+-----+-------+
| | A | B |
+---+-----+-------+
| 1 | 1A | 0001A |
+---+-----+-------+
| 2 | 38R | 0038R |
+---+-----+-------+
| 3 | 22R | 0022R |
+---+-----+-------+
| 4 | 7A | 0007A |
+---+-----+-------+
| 5 | 41R | 0041R |
+---+-----+-------+
| 6 | 64A | 0064A |
+---+-----+-------+
RESULT
+---+-----+-------+
| | A | B |
+---+-----+-------+
| 1 | 1A | 0001A |
+---+-----+-------+
| 2 | 7A | 0007A |
+---+-----+-------+
| 3 | 22R | 0022R |
+---+-----+-------+
| 4 | 38R | 0038R |
+---+-----+-------+
| 5 | 41R | 0041R |
+---+-----+-------+
| 6 | 64A | 0064A |
+---+-----+-------+

Related

Excel - How to countif within column B excluding duplicate values from column A?

The spreadsheet I am working with houses multiple duplicates for CLIENT_ID and I want to be able to count each CLIENT_ID only once, and then count the amount of a specified value within AGE_CATEGORY. Basically I want to exclude any duplicates and then countif.
| Column A | Column B |
+-----------+--------------+
| CLIENT_ID | AGE_CATEGORY |
| 1514 | 65 |
| 1517 | 65 |
| 1522 | 17 |
| 1519 | 37 |
| 1514 | 65 |
| 1516 | 28 |
| 1503 | 20 |
--- I would like for the count for people >=65 to be 2, since client# 1514 appears twice.
How can I do it?
What you need is first extract unique values from column A then count those IDs. As per my below screenshot use below formulas ExcelO365 formulas.
D2 =UNIQUE(A2:A8)
E2 =COUNTIF(A2:A8,D2#)
Create a list of unique age (category?) values — say, in Column D
— with “Data” → “Sort & Filter” → “Advanced (Filter)”. 
(Sort them if you want.) 
Enter
=SUM(--(FREQUENCY(IF(B$2:B$8=D2,A$2:A$8),A$2:A$8)>0))
into E2, press Ctrl+Shift+Enter,
and copy/drag down. 
This is the result:
| A | B | C | D | E |
---+-----------+--------------+--------------+--------------+-------+
1 | CLIENT_ID | AGE_CATEGORY | | AGE_CATEGORY | |
2 | 1514 | 65 | | 65 | 2 |
3 | 1517 | 65 | | 17 | 1 |
4 | 1522 | 17 | | 37 | 1 |
5 | 1519 | 37 | | 28 | 1 |
6 | 1514 | 65 | | 20 | 1 |
7 | 1516 | 28 | | | |
8 | 1503 | 20 | | | |
Based on this answer by SandPiper.
Assuming your data (to return values) is in A2:A8 and criteria is in B2:B8 use this ARRAY formula to check unique values >=65
=SUM(--(FREQUENCY(IF($B$2:$B$8>=65,MATCH($A$2:$A$8, $A$2:$A$8,0)),ROW($A$2:$A$8)-ROW($A$2)+1)>0))
Note for array formula you have to enter this formula with ctrl + shift + enter so that curly braces appear around the formula automatically.
Needless to say, you can change >=65 to your criteria accordingly. sample check see screenshot

How to divide two cells based on match?

In a table 1, I have,
+---+---+----+
| | A | B |
+---+---+----+
| 1 | A | 30 |
| 2 | B | 20 |
| 3 | C | 15 |
+---+---+----+
On table 2, I have
+---+---+---+----+
| | A | B | C |
+---+---+---+----+
| 1 | A | 2 | 15 |
| 2 | A | 5 | 6 |
| 3 | B | 4 | 5 |
+---+---+---+----+
I want the number in second column to divide the number in table 1, based on match, and the result in third column.
The number present in the bracket is the result needed. What is the formula that I must apply in third column in table 2?
Please help me on this.
Thanks in advance
You can use a vlookup() formula to go get the dividend. (assuming table 1 is on Sheet1 and table 2 in Sheet2 where we are doing this formula):
=VLOOKUP(A1,Sheet1!A:B, 2, FALSE)/Sheet2!B1
Since you mention table, with structured references, though it seems you are not applying those here:
=VLOOKUP([#Column1],Table1[#All],2,0)/[#Column2]

excel formula series fill in custom order

i have two table of excel
1st/
1 | blawa1 |blawb1 |blawc1 |blawd1 |
2 | blawa2 |blawb2 |blawc2 |blawd2 |
3 | blawa3 |blawb3 |blawc3 |blawd3 |
...
2nd/ that should be linked to 1st table in the folowing form
1 | blawa1 |
2 | blawb1 |
3 | blawc1 |
4 | blawd1 |
5 | |
6 | blawa2 |
7 | blawb2 |
8 | blawc2 |
9 | blawd2 |
10 | |
11 | blawa3 |
12 | blawb3 |
13 | blawc3 |
14 | blawd3 |
15 | |
16 | blawa4 |
17 | blawb4 |
18 | blawc4 |
19 | blawd4 |
20 | |
...
when i write the formula in table 2 and drag it down, the formula did not fill in series that i want.
e.g: it jump from "blawa1" to "blawa6" , while it should be "blawa2"
With data in columns A through D, pick some cell, say F4, and enter:
=OFFSET($A$1,ROUNDUP(ROWS($1:1)/5,0)-1,MOD(ROWS($1:1)-1,5))
and copy down:
Using similar formulas, any two dimensional table can be mapped into a single column or a single row.
If you see zeros in the output single column rather than the spaces, fill column E with blanks.
You can use the below formula
=IF(INDIRECT(CHAR(64+MOD(ROW()+4,5)+1) & (INT((ROW()-1)/5)+1))=0,"",INDIRECT(CHAR(64+MOD(ROW()+4,5)+1) & (INT((ROW()-1)/5)+1)))
copy the this cell to required number of times.

COUNTIF Function, reset count if value equals a specific value

I need to list a running count in column A of each occurrence of the value "4A" in column B, but the count needs to reset to 0 if the value in column B equals "2B".
I have attached a sample of my workbook, column A shows how I need the count to operate. I am open to using VB or a formula.
Or in text format:
| A | B |
+---+----+
| 0 | 2B |
| | 3A |
| 1 | 4A |
| | 4B |
| | 4B |
| 2 | 4A |
| | 4B |
| 3 | 4A |
| | 9A |
| 0 | 2B |
| | 3A |
| 1 | 4A |
| | 4C |
| 2 | 4A |
| | 9A |
| 0 | 2B |
| | 3A |
| 1 | 4A |
| | 9A |
| 0 | 2B |
| | 3A |
| 1 | 4A |
| | 4C |
| | 9A |
| | 9B |
| | 9Z |
EDIT:
#Jeeped and #trincot proposed better non-array versions. I modified them slightly here:
#Jeeped's formula:
=IF(OR(B1={"2B","4A"}), COUNTIF(INDEX(B:B,AGGREGATE(14, 6, ROW(B$1:B1)/(B$1:B1="2B"), 1)):B1, "4A"),"")
After modification it uses LARGE function in the aggregate rather than SMALL and "" instead of TEXT(,).
#trincot's formula:
=IF(OR(B2={"2B","4A"}),(B2="4A")*(1+IFERROR(INDEX(G:G,MATCH(MAX(G$1:OFFSET(G2,-1,0))+1,G$1:OFFSET(G2,-1,0))),0)),"")
Compared to original, it's been rearranged slightly 'IF-wise', I also replaced magic 9999 with MAX([...]) + 1 and made it so that you can just paste it in 1st cell and drag down rather than have two separate formulas for first cell and the consecutive ones.
My original version:
I think it has the benefit of perhaps being the easiest to understand (? - I am obviously biased here so I might be wrong) and it's physically the shortest of all.
It has the obvious drawback of being an array-formula.
In cell "A1" you can write:
=IF(OR(B1="2B",B1="4A"),SUM((B$1:B1="4A")*(ROW(B$1:B1)>MAX(ROW(B$1:B1)*(B$1:B1="2B")))),"")
It's an array formula so you have to confirm it with ctrl + shift + enter.
Then you can drag it down.
Basically it counts number of occurrences of "4A" in a range extending from current row to the first provided that rows of counted "4A" are larger than that last row of "2B".
Here is a way with standard (non-array) formulas:
In A1 put:
=IF(B1="4A",1,0)
In A2 put:
=IF(B2="2B",IF(INDEX(A:A,MATCH(9999,A$1:A1))>0,0,""),
IF(B2="4A",1+INDEX(A:A,MATCH(9999,A$1:A1)),""))
Drag/copy A2 down to the remaining cells in the A column.
This will produce blanks where otherwise the same value would be displayed.
If repeating values don't need to be suppressed, then you can simplify the formula in A2 to:
=IF(B2="2B",0,IF(B2="4A",1+A1,A1))
... and copy it down.

Count text occurrences in a column in Excel

I have the following list in Excel:
+-------+----------+
| am | ipiresia |
+-------+----------+
| 50470 | 29 |
| 50470 | 43 |
| 50433 | 29 |
| 6417 | 51 |
| 6417 | 52 |
| 6417 | 53 |
| 4960 | 25 |
| 4960 | 26 |
| 5567 | 89 |
| 6716 | 88 |
+-------+----------+
I want to add a column, let's say 'num' and count the occurrences of column 'am' in a row adding one when a new occurrence happens as follows:
+-------+----------+-----+
| am | ipiresia | num |
+-------+----------+-----+
| 50470 | 29 | 1 |
| 50470 | 43 | 2 |
| 50433 | 29 | 1 |
| 6417 | 51 | 1 |
| 6417 | 52 | 2 |
| 6417 | 53 | 3 |
| 4960 | 25 | 1 |
| 4960 | 26 | 2 |
| 5567 | 89 | 1 |
| 6716 | 88 | 1 |
+-------+----------+-----+
Is it possible to get this automatically with a formula in Excel?
yes,
my example:
(assume you start your table containing 3 columns at Excels origin at A1 without header lines)
Then fill C1 with value "1"
and then start in C2 with entering a formula
simple like this:
=if($A2=$A1;$C1+1;1)
then you drag C2 down at the cells downright located autofill position as far as you want. Most times also double click works to let Excel autofill the columns down to the end of you prefilled table.
If you need assistance for AutoFill press F1 in Excel an the help with tell you in detail.
Assuming the sample table starts at A1 (with headers) the following formula will provide the expected results even if the list is not sorted.
=COUNTIF($A$1:$A2,A2)
Enter the formula at cell C2 then paste it down to the last cell of the data (or use AutoFill)

Resources