Split text and number, then convert and add numbers - excel

I have a series of values such as:
10RP
2.5R
5R
7.5R
10R
2.5YR
5YR
I want to convert the string portion to a number based on this table:
0 R
10 YR
20 Y
30 GY
40 G
50 BG
60 B
70 PB
80 P
90 RP
I then want to create two columns so that:
2.5YR
becomes:
2.5 10
In a third column I will add the two numbers together.
Can this be done just using formulas? I want to avoid using VBA if I can.
Thanks.

Here's another approach.
seq is a defined name referring to an array constant ={1,2,3,4,5}
If you might have numbers that encompass more than five characters, just extend the constant appropriately.
Number part: =LOOKUP(9E+307,--MID(A1,1,seq))
Letter portion converted to number:
=VLOOKUP(MID(A1,LOOKUP(2,1/ISNUMBER(-MID(A1,1,seq)),seq)+1,9),$F$1:$G$10,2,FALSE)
Where your table is in F1:G10 and reversed so that the letters are in the first column

This might not be the most efficient but should work
=IFERROR((LEFT(F3,LEN(F3)-2)+VLOOKUP(RIGHT(F3,2),$A$3:$B$12,2,0)),
(LEFT(F3,LEN(F3)-1)+VLOOKUP(RIGHT(F3,1),$A$3:$B$12,2,0)))
Where your lookup table is A3:B12 with the letters in the left-most column
Check for the two-letter combinations before the single-letter ones.

Related

[Excel][Math] Formula to generate numbers between two limits

I am trying to fill a column in Excel with values that are generated randomly but the sum of all the values total to the end.
Example:
Starting value = 320
Final value = 350
Need to generate 2 more values which have random difference between them but total to 350 at the end, as in: 2nd val = 12, 3rd val = 18.
The script/formula should generate different values when run next (for another table etc.). It may generate, for the same starting and final values, 15 and 15 or 8 and 22 for the 2nd and 3rd values respectively etc.
Basically what the formula should do is: Find the difference between the starting and final values then randomly add a number to create the 2nd entry. Now the third entry should follow the same pattern but the value generated should end up totaling to the final.
The example is only for 2 values but I'm working on tables ranging from 15-30+ values.
I don't know if Excel can do it, or if there's a mathematical formula that will work here.
Thanks in advance for all the help!
You need something like this:
That gives:
The trick is to generate a list of uniform random numbers between 0 and 1 and then scale those numbers up the total that you're looking for.

Is there a way to find any one of a set of characters using an excel formula

I have data that uses a range, or a less than symbol to denote 'between 0 and number'. But multiple characters are used for the same purpose.
It looks like below (first two columns), plus a column showing the results I want:
Country
Average hotdog consumption
Desired output
Madeupaland
10-200
105
Exampledesh
50—1000
525
Republic of Notreal
<1000
500
Inventia
≤5000
2500
Plus many rows where the data in the second column is purely numerical and doesn't need finessing into a number
I can use this formula to calculate the midpoint where there is a range:
=IFERROR(AVERAGE(LEFT(C2,FIND("–",C2)-1),RIGHT(C2, LEN(C2)-FIND("–",C2))), A2)
But they only covers one kind of dash(- and not —). Similarly, if I want to halve the numbers in rows with < and ≤ I'd need to replicate a formula there.
Is there a way of finding multiple different characters from a set? My understanding is that find looks for the whole string of characters. substitute is a work around, but I'd have to substitute every different value in the 'character set'.
In regex this would just be [-—].
I'm using Excel 2013 if that matters
It's not a perfect solution but you can try the following. This replaces those patterns of text with replacements representing which formula to use:
Create a Reference Table (I have made this in I1:K5)
|Pattern |Pattern Name |Substitution Rule |
|------- |------------ |----------------- |
|— |double dash |/2+0.5* |
|- |dash |/2+0.5* |
|< |lt |0.5* |
|≤ |lte |0.5* |
In your third column enter the following array formula (Using Ctrl + Shift + Enter to confirm)
=IF(ISNUMBER(B2),B2,"'="&SUBSTITUTE(B2,INDEX($I$2:$I$5,MIN(IF(ISNUMBER(FIND($I$2:$I$5,B2)),ROW($I$2:$I$5)-1,99))),INDEX($K$2:$K$5,MIN(IF(ISNUMBER(FIND($I$2:$I$5,B2)),ROW($I$2:$I$5),99)-1))))
Copy your third column and past values into a fourth column
Replace all the ''s with nothing to evaluate the expressions using Ctrl + H
My Result:
Country
Average hotdog consumption
Desired output
Formula Paste
Output after replacing 's
Madeupaland
10-200
105
'=10/2+0.5*200
105
Exampledesh
50—1000
525
'=50/2+0.5*1000
525
Republic of Notreal
<1000
500
'=0.5*1000
500
Inventia
≤5000
2500
'=0.5*5000
2500

Excel: count amount of characters

I have to calculate a price by single character. In my example I have 110 parts that are numbered, so this means I have:
9 parts with one character (1 > 9)
90 parts with two characters (10 > 99)
11 parts with three characters (100 > 110)
Thus there are 222 characters for this price.
Is there a way to calculate this with a (nested) formula ? I've been thinking about since a few days and can't come with a solid & modular formula.
See "manual"-Excel calculation here below.
Thanks for your help.
Do you mean:
=SUM(LEN(SEQUENCE(110)))
Or for non-Microsoft 365 versions:
=SUMPRODUCT(LEN(ROW(A1:INDEX(A:A,110))))
If you want to calculate the number of characters of a list of values that is not a continuous sequence starting with 1 up to e.g. 110, then you can do it with the following formula:
=SUM(COUNTIFS(list,">=1",list,"<=9")*1,COUNTIFS(list,">=10",list,"<=99")*2,COUNTIFS(list,">=100",list,"<=999")*3)
Note: the term "list" is just a name that refers to a range of Excel cells.

Pulling out specific characters that are combined in a single column

I have a data extract that resulted in fields being combined into column A like this:
Sales Figures Report pg 121
Walmart Inc. 001230134 99 Associates Parkway 56.12 20.00 10.00 86.12 00 1
1400.25 262.40 14.50 1677.15 02 9
50.00 100.25 10.00 160.25 00 1
1400.25 262.40 14.50 1677.15 02 9
There are over 50,000 rows in this sort of format, some are a little different as they'll start with vendor information and then have those values after (still all in col. A). In the above example 1677.15 is the combined value of the three numbers before that, i.e. the total amount due.
Originally I wanted to basically separate out each value using things like left(), mid(), right() etc. however at this point all I want is the total figure, i.e. the $1677.15 in the above example. What is the best non-vba method of doing this?
Two issues:
The problem is that the amounts are not always the same number of digits (can range from $xx.xx to $xxx,xxx.xx)
Since There are multiple "." you can't use search() to find the correct character location.
In your example, the Total figure is always the third group from the end. That being the case, you can use the following formula and defined names:
=IFERROR(--INDEX(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",99)),seq_99,99)),LEN(A1)-LEN(SUBSTITUTE(A1," ",""))-1),"")
Defined Names
seq refers to: =ROW(INDEX($1:$65535,1,1):INDEX($1:$65535,255,1))
seq_99 refers to: =IF(seq=1,1,(seq-1)*99)
In the formula,
SUBSTITUTE: Replace all spaces with a large number (99) of spaces
MID Return an array consisting of each word (space separated)
TRIM the words to remove the extra spaces
INDEX Return the item that is third from the end.
IFERROR handle lines such as your first, which does not contain the relevant pattern.
seq and seq_99 return arrays of {1,2,3,...}and{1,99,198,...}` to be used in the formulas

Excel formula to generate series for 3 digit

I am looking for generating alpha numeric series of 3 digits as below:
0A0 to 9Z9
i.e. 0A0, 0A1,... 0A9, 0B0.... 9Z9
Is there any way in excel to generate the above sequence?
I tried many formulas but not able to do with alpha numeric.
You can try, in some cell:
=INT((ROWS($1:1)-1)/260)&CHAR(MOD(INT((ROWS($1:1)-1)/10),26)+65)&MOD(ROWS($1:1)-1,10)
Then fill down to a total of 2600 rows
EDIT: If you want to repeat the sequence after 2600 rows, then try:
=MOD(INT((ROWS($1:1)-1)/260),10)&CHAR(MOD(INT((ROWS($1:1)-1)/10),26)+65)&MOD(ROWS($1:1)-1,10)
It's easy!
You're trying to =CONCATENATE() a series made of random integers and random strings.
a RANDOM INTEGER from 0 to 9 --------------- =RANDBETWEEN(0;9)
a RANDOM CHARACTER from A to Z --------- =CHAR(RANDBETWEEN(65;90)) ¹
a RANDOM INTEGER from 0 to 9 --------------- =RANDBETWEEN(0;9)
¹ See more at ASCII Character Map
Final Formula:
=CONCATENATE(RANDBETWEEN(0;9);CHAR(RANDBETWEEN(65;90));RANDBETWEEN(0;9))
So, we used:
=CONCATENATE()
=RANDBETWEEN()
=CHAR()
An ASCII Character Map
Or if you're not interested in random numbers and chars, should be easy to create a column with the necessary numbers to generate a specific sequence.
But.... if you want all combinations possible using these variables, or in numbers, all the 2500 combinations possible, you should create a macro. I mean... it's doable using formulas, but is way easier to accomplish this using vba.

Resources