Extract numbers before any letter or special sign within cell content - excel

I have the following Excel spreadsheet:
A B C
1 125Product 125
2 58968Brand 58968
3 74Category 74
4 6325Product 6325
5 2:2 2:
6 7489Category458 7489Bra
7 29:Brand 29
8
In Column A I have contents consisting of numbers, letters or special characters.
In Column B I want to extract all numbers before any letter or special character; therefore, I use the following formula:
=LEFT(A2,SUM(LEN(A2)-LEN(SUBSTITUTE(A2,{"0","1","2","3","4","5","6","7","8","9"},""))))
This formula works for all values except for the values in Cell A5 and A6.
I guess the issue is that in this cell - instead of all the other values - there is a another number after the letter/special character.
What do I need to change in my formula to only extract the numbers before any letter or special character?

Formula used in B1:
=LEFT(A1,MATCH(FALSE,ISNUMBER(MID(A1,ROW($A$1:INDEX(A:A,LEN(A1))),1)*1),0)-1)
Confirm through Ctrl+Shift+Enter
If you don't want to enter as array, use:
=LEFT(A1,MATCH(FALSE,INDEX(ISNUMBER(MID(A1,ROW($A$1:INDEX(A:A,LEN(A1))),1)*1),0),0)-1)

Related

Excel - Match cell values in 2 separate columns and paste a different value if match

=INDEX(C:C,MATCH(A1,B:B,0))
The above formula is being pasted in D1.
I need it to return the C cell that on the same row as the matching A and B fields:
A B C D
77 22 MO91117
88 88 MO91337
99 99 MO12347
22 77 MO91837
Ideally, if I ran the formula in D1, it would return M091837.
Any help would be greatly appreciated!
Answering for completeness. Credit to A.S.H for the answer (in the comments of the question).
Ensure that both columns that you are trying to match are formatted similarly. It looks like the error in this question was that one column was formatted as text, and one column was formatted as a number. As an example the number 4 and the character 4 are represented differently in software, thus not returning expected values when trying to match text and numbers.

How do I split a row of text into different columns according to number of characters using a macro in Microsoft Excel?

I want to know if I can use a macro in Excel to separate data in a single column into different colums according to number of characters. For example, what I have is this in column A
A
AB
ABC
1A
564
8
What I need is this, in colums A, B and C
A AB ABC
8 1A 564
Thanks.
Use the following formula in a new column B next to Column A:
=IFERROR(INDEX($A$1:$A$6,SMALL(IF(LEN($A$1:$A$6)=1,ROW($A$1:$A$6),99999),ROW()),1),"")
Array Formula press Ctrl+Shift+Enter at the same time
and drag it down, it will write the Values of B whose Length is 1, and when it gives empty it means no more Values with Length 1
Small will find the Cell which length is 1 (Row()=1, 1st cell which length=1, Row()=2, 2nd cell which length =1 ...)
If will return all the rows for the corresponding condition
Index will return the Cell
Iferror return empty "" if no more match
For the second column write 2 instead of 1 in LEN($A$1:$A$6)=2
=IFERROR(INDEX($A$1:$A$6,SMALL(IF(LEN($A$1:$A$6)=2,ROW($A$1:$A$6),99999),ROW()),1),"")
For the third column write 3 in LEN($A$1:$A$6)=3
=IFERROR(INDEX($A$1:$A$6,SMALL(IF(LEN($A$1:$A$6)=3,ROW($A$1:$A$6),99999),ROW()),1),"")

Generate Column of raw data based on frequency table in Excel

I have a column of numbers and a second column of numbers. The second column of numbers contains the frequency of the numbers in the left column.
I want to create a third column of numbers that has the raw data.
Example:
A B
1 5
3 2
4 4
Column C would look like:
C
1
1
1
1
1
3
3
4
4
4
4
How can I do that in Excel? Thanks!
Based on data in A1:B3, in C1, array formula**:
=IF(ROWS(A$1:A1)>SUM(B$1:B$3),"",INDEX(A$1:A$3,MATCH(TRUE,MMULT(0+(ROW(A$1:A$3)>=TRANSPOSE(ROW(A$1:A$3))),B$1:B$3)>=ROWS(A$1:A1),0)))
and copied down until you start to get blanks for the results.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

Formula to count each individual digit in a cell per column in Excel

I have a list of numbers like below. And I need to know how many of each number are in each cell per column.
My List
1
2
3
4
10
11
12
13
14
21
22
23
24
I need to know how many times 1 occurs throughout the whole list, including double digit numbers, and I need to do this for each number 0-9. The reason I don't just count them is because I have a total of 1,400 numbers that I need to break down. I have tried =COUNTIF but unfortunately it sees numbers such as 22 and ONE number, when I need it to tell me that there are 2, 2s. Is there a way? Thanks!
With your data in A2:A15 and the digit to count in B2 you can use following array formula (confirmed with Ctrl+Shift+Enter):
=SUM(LEN(A2:A15)-LEN(SUBSTITUTE(A2:A15,B2,"")))
This would be a way of doing it:-
=SUM(LEN(A$1:A$10)-LEN(SUBSTITUTE(A$1:A$10,"1","")))
and the same for "2", "3" etc. or put digits 0-9 in a range of cells starting at (say) B1 and enter this in C1 and pull down:-
=SUM(LEN(A$1:A$10)-LEN(SUBSTITUTE(A$1:A$10,B1,"")))
Is an array formula and must be entered with CtrlShiftEnter
To count 1's, use something like:
=SUMPRODUCT(LEN(A2:A14)-LEN(SUBSTITUTE(A2:A14,"1","")))
You can count any digit or character or substring this way.
If you're only ever considering up to double-digit numbers, as you appear to suggest:
=SUMPRODUCT(0+(MID(A$1:A$10,{1,2},1)="1"))
Or, more dynamically, with e.g. 1 in B1:
=SUMPRODUCT(0+(MID(A$1:A$10,{1,2},1)=""&B1))
and copied down.
Regards

divide duplicate values by the number of duplicates for that value

I want to write a VBA code or excel formula that will divide duplicate values by the number of duplicates for that value. For example
A- 6
B- 8
C- 3
D- 4
F- 5
A- 8
A- 4
The code would add 6+8+4 and then divide by 3. It would replace each current value for A with 6.
Meh...
Say column A contains your letters, Column B contains your numbers, and row 1 is a header row. Enter this formula in cell C2 and pull it down:
=B2/COUNTIF(A:A,A2)
You can use an Averageif formula
=AVERAGEIF(A:A,A2,B:B)

Resources