Using the substitution formula to calculate the average of two numbers

mrichard

New Member
Joined
Mar 23, 2020
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I am trying to calculate the average of the following which is text in my excel worksheet:
Cell A1 has >=$1M and <$2M

I have used the substitution formula to remove the >= and < and $.

So now I am left with this:
1M and 2M

Is there a way to convert the 1M and 2M into 1,000,000 and 2,000,000 and take the average.
So it would equal 1,500,000.

Just thought somebody would have done this before.

Thanks for any help in advance

Mark
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
=VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(E17,">",""),"M",""),"<",""),"=",""))*1000000
 
Upvote 0
With a UDF:

VBA Code:
Function SumTextNumbers(TextString As String, Optional strDelim As String = " ") As Double
'
    Dim xNums As Variant, lngNum As Long
    
    xNums = Split(TextString, strDelim)
'
    For lngNum = LBound(xNums) To UBound(xNums)
        SumTextNumbers = SumTextNumbers + Val(xNums(lngNum))
    Next lngNum
End Function

And then this formula:

VBA Code:
=SumTextNumbers(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,">",""),"=",""),"<",""),"$",""),"M","000000"),"and",""))/2
 
Upvote 0
Here is a formula only approach:

VBA Code:
=SUM((LEN(A1)-LEN(SUBSTITUTE(A1,{1,2,3,4,5,6,7,8,9},"")))*{1,2,3,4,5,6,7,8,9})/2*1000000
 
Upvote 0
A UDF, which also works with number larger than 10. (>=$250M and <$21M)

Put this behind a module:
VBA Code:
Function jec(cell As String) As Double
 With CreateObject("VBScript.RegExp")
   .Global = True
   .Pattern = "[^\d+\s]"
   jec = Evaluate(Replace(Application.Trim(.Replace(cell, "")), " ", "+")) / 2 * 1000000
 End With
End Function

Then call the function as
Excel Formula:
=jec(A1)
 
Upvote 0
One example is not much to go on. ;)

If your question has not been fully resolved by any of the above suggestions, can you clarify if all numbers are "M" numbers or might there also be "K" numbers or numbers with no immediately following letter?
Perhaps 5 to 10 varied examples of your data and the expected results might help clarify.
 
Upvote 0

Forum statistics

Threads
1,215,215
Messages
6,123,668
Members
449,114
Latest member
aides

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top