Understanding Formula

zaska

Well-known Member
Joined
Oct 24, 2010
Messages
1,046
Hi all,

I would request anyone to unravel the following formula as i am unable to understand it's logic.


=SUMPRODUCT(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1)+0)


Thank you
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hello sir,

The context is to findout the sum of all digits in a cell and i am unable to understand this formula. I don't have any clue about MID , ROW, OFFSET and SUMPRODUCT hence missing the logic behind

Thank you
 
Upvote 0
Let's assume the number 1235 is in A1.

Start with the OFFSET. OFFSET($A$1,,,LEN(A1)) creates a range with the same height as the number of characters in A1.
The ROW function then returns the row values of that bogus range, starting with 1, so you get {1,2,3,4} representing the positions in the value of A1.
MID will pull each of those positions in turn so you get effectively, MID(A1,1,1);MID(A1,2,1);MID(A1,3,1);MID(A1,4,1) -- the four digits in A1, each isolated as a single digit.
SUMPRODUCT loops through, adding "1","2","3","5" together to give 11, the final answer. Note: the +0 is a way to convert text "numbers" to numbers

Denis
 
Last edited:
Upvote 0
Hi all,

I would request anyone to unravel the following formula as i am unable to understand it's logic.


=SUMPRODUCT(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1)+0)


Thank you

It's identical to:

=SUMPRODUCT(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)+0)

The ROW bit creates an integer array of 1 to the length of the value in A1...

If A1 is 6718, the length of A1 is 4. So we need an integer array of 1, 2, 3, and 4.

The OFFSET bit will produce:

{1;2;3;4}

Fed to MID, we get:

MID(A1,{1;2;3;4},1)

===>

{"6";"7";"1";"8"}

which is an array of text numbers.

If you coerce this using +0, we get:

{6;7;1;8}

Fed to SumProduct, we get: 22
 
Upvote 0
Sir,

I tried using only the offset in excel sheet and it turned zero. I am still in confusion. Can you kindly Show the calculation as to what exactly the formula does.

I didn't understand where the offset formula creates a equal height.

Thank you
 
Upvote 0
It's identical to:

=SUMPRODUCT(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)+0)

The ROW bit creates an integer array of 1 to the length of the value in A1...

If A1 is 6718, the length of A1 is 4. So we need an integer array of 1, 2, 3, and 4.

The OFFSET bit will produce:

{1;2;3;4}

Fed to MID, we get:

MID(A1,{1;2;3;4},1)

===>

{"6";"7";"1";"8"}

which is an array of text numbers.

If you coerce this using +0, we get:

{6;7;1;8}

Fed to SumProduct, we get: 22

Thank you sir. I understood the formula clearly.
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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