Correct Formula for This Combination

Jasa P

Board Regular
Joined
Feb 6, 2012
Messages
68
Good morning,

I'm trying to get a solution for my problem. I'm sure this is fairly simple, but I don't know how to resolve this combination. So, I need your help.

I have a combination of
20.10.10x5.15.25/
in cell A1

The problem are:
a. The result for combination before "x" should be the amount of dots (.) + 1, so the result is 3
b. The result for combination between "x" and "/" should be the sum of the numbers, so the result is 45

Then, the results from a and b must be multiplied, so the final result is 135 in cell B1

I'm using Excel 2007 and Windows XP

I'm sorry for my poor English.
Any help would be great. Thank you.

Best Regards

Jasa
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Good morning,

I'm trying to get a solution for my problem. I'm sure this is fairly simple, but I don't know how to resolve this combination. So, I need your help.

I have a combination of
20.10.10x5.15.25/
in cell A1

The problem are:
a. The result for combination before "x" should be the amount of dots (.) + 1, so the result is 3
b. The result for combination between "x" and "/" should be the sum of the numbers, so the result is 45

Then, the results from a and b must be multiplied, so the final result is 135 in cell B1

I'm using Excel 2007 and Windows XP

I'm sorry for my poor English.
Any help would be great. Thank you.

Best Regards

Jasa
This works on the single example you posted. It's usually a good idea to post several examples so we can see if the data is consistent.

Array entered**:

=(LEN(LEFT(A2,SEARCH("x",A2)))-LEN(SUBSTITUTE(LEFT(A2,SEARCH("x",A2)),".",""))+1)*SUM(IF(MID("."&MID(A2,SEARCH("x",A2)+1,20),COLUMN(1:1),1)=".",--(0&MID(MID(A2,SEARCH("x",A2)+1,20),COLUMN(1:1),FIND(".",MID(SUBSTITUTE(A2,"/","."),SEARCH("x",A2)+1,20),COLUMN(1:1))-COLUMN(1:1)))))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.

As you can see, that formula is quite complicated and is calculation intensive. I think you'd be better off with a VBA user defined function. I'm not much of programmer so someone else will need to help you with that.
 
Upvote 0
I got the result is Value. VBA user? So, Should I post new thread and use "VBA" for the title? thank you so much.
 
Upvote 0
I got the result is Value. VBA user? So, Should I post new thread and use "VBA" for the title? thank you so much.
The formula worked for me:

Book1
AB
1StringResult
220.10.10x5.15.25/135
Sheet1

Did you enter the formula as an array formula?

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
As far as using a VBA solution, if after a period of time has passed and no one has replied with a VBA solution then you should start a new thread. A reasonable period of time would be about 1 day.
 
Upvote 0
i found this pretty tricky to do quickly in vba...

split was the first thing i thought of using, split by "x" then count dots on left and then split by "." on the right, and sum the result.

this wasn't all that fast, and so i tried a byte array approach, which is my sort of goto method when dealing with strings. this function is the result of that approach, but is not much faster than the formula based approach that was supplied.

the overhead of vba udf calls makes it difficult to compete with even complex formulas.

this makes a bunch of assumptions about your data, and will cause problems if the supplied example is not consistent with the rest of your data.

Code:
Function funnySum(vStr As String) As Long
Dim bArr() As Byte, conCnt As Long
Dim dotCnt As Long, isLeft As Boolean

If vStr = vbNullString Then Exit Function
bArr = Left(vStr, InStr(1, vStr, "/") - 1)

For i = UBound(bArr) - 1 To 0 Step -2
    If isLeft Then
        If bArr(i) < 47 Then dotCnt = dotCnt + 1
    Else
        If bArr(i) > 48 Then
            If bArr(i) < 58 Then
                funnySum = funnySum + (bArr(i) - 48) * 10 ^ conCnt
                conCnt = conCnt + 1
            ElseIf bArr(i) = 120 Then
                isLeft = True
            End If
        Else
            conCnt = 0
        End If
    End If
Next

funnySum = funnySum * (dotCnt + 1)

End Function
 
Last edited:
Upvote 0
The formula worked for me:

Sheet1

<table style="font-family:Verdana,Arial; font-size:10pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; " border="0" cellpadding="0" cellspacing="0"> <colgroup><col style="font-weight:bold; width:30px; "><col style="width:136px;"><col style="width:72px;"></colgroup><tbody><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td> </td><td>A</td><td>B</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">1</td><td style="text-align:center; border-style:solid; border-width:1px; border-color:#000000; ">String</td><td style="text-align:center; border-top-style:solid; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">Result</td></tr><tr style="height:17px ;"><td style="font-size:8pt; background-color:#cacaca; text-align:center; ">2</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-left-style:solid; border-width:1px; border-color:#000000; ">20.10.10x5.15.25/</td><td style="text-align:center; border-right-style:solid; border-bottom-style:solid; border-width:1px; border-color:#000000; ">135</td></tr></tbody></table>


Did you enter the formula as an array formula?


As far as using a VBA solution, if after a period of time has passed and no one has replied with a VBA solution then you should start a new thread. A reasonable period of time would be about 1 day.

Hi, thank you so much. It works, thank u. :) Thank u for helping me
 
Upvote 0
just for completeness there is a mistake in the vba method that 48 should be 47.

i would also probably go with the formula approach on this one!
 
Upvote 0
i found this pretty tricky to do quickly in vba...

split was the first thing i thought of using, split by "x" then count dots on left and then split by "." on the right, and sum the result.

this wasn't all that fast, and so i tried a byte array approach, which is my sort of goto method when dealing with strings. this function is the result of that approach, but is not much faster than the formula based approach that was supplied.

the overhead of vba udf calls makes it difficult to compete with even complex formulas.

this makes a bunch of assumptions about your data, and will cause problems if the supplied example is not consistent with the rest of your data.

Code:
Function funnySum(vStr As String) As Long
Dim bArr() As Byte, conCnt As Long
Dim dotCnt As Long, isLeft As Boolean

If vStr = vbNullString Then Exit Function
bArr = Left(vStr, InStr(1, vStr, "/") - 1)

For i = UBound(bArr) - 1 To 0 Step -2
    If isLeft Then
        If bArr(i) < 47 Then dotCnt = dotCnt + 1
    Else
        If bArr(i) > 48 Then
            If bArr(i) < 58 Then
                funnySum = funnySum + (bArr(i) - 48) * 10 ^ conCnt
                conCnt = conCnt + 1
            ElseIf bArr(i) = 120 Then
                isLeft = True
            End If
        Else
            conCnt = 0
        End If
    End If
Next

funnySum = funnySum * (dotCnt + 1)

End Function

Sorry, but I'm confused :confused:. Can you tell me a general way, please. Thank you so much. Sorry for making difficult.
 
Upvote 0
just for completeness there is a mistake in the vba method that 48 should be 47.

i would also probably go with the formula approach on this one!

Thank u for helping me. I'm sure it'll useful, I'm trying to understand the VBA code. :)
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,827
Members
449,470
Latest member
Subhash Chand

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