How to SUM & COUNT Between Two Text Strings?

mzi

New Member
Joined
Apr 29, 2012
Messages
31
I want to SUM and COUNT Values between two text strings

Suppose in Row1, I have values like this
1,0,2,OUT,4,.,.,1,6,OUT,1,3

Now I want to SUM & COUNT Values Before, Between and After the Text "OUT"...
So,
For the SUM Function, the result should be
3 in the Cell A2, 11 in the Cell B2 and 4 in the Cell C2...
For the COUNT Function, the result should be
3 in the Cell A3, 5 in the Cell B3 and 2 in the Cell C3...

I'll be very thankful if you help me...
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
It isn't clear ..

- if there can be more (or less) than 2 OUT values in the row, but there will be at least one OUT

- if there are lots of rows like this to deal with

- if there is a maximum number of columns that the data can occupy

My suggestion below assumes ..

- there can be more/less than 2 OUT values in the row

- the are not too many of these rows to deal with as I have used the volatile OFFSET function which may adversely affect your sheet performance if too many of these formulas are used on your sheet.

- data does not go beyond column Z

- that you are using Excel 2007 or later


Formulas in column A are stand-alone
Formulas in column B are copied across as far as you might need
Row 4 is used as a helper row.

These formulas may need further tweaking depending on just what might occur in your sheet.

If this doesn't meet your needs, please give more examples of sample data and expected results.

Excel Workbook
ABCDEFGHIJKLM
1102OUT4..16OUT13
23114
3352
441026
5
mzi
 
Upvote 0
Hi,

This got me curious, so I searched around and came up with the following, none of which are my solutions, except for the Substitute formula!!

Excel Workbook
ABCDEFGH
1LeftMiddleRight
210241613102OUT416OUT131,0,2,OUT,4,.,.,1,6,OUT,1,3
3Sum3114
4Count332
Sheet6


I hope that helps.

Good luck.

Ak
 
Upvote 0
Another suggestion.

This should handle any length of row after Column D, provided "OUT" appers twice in the row.
(D1:O1 is only for a check, it isn't required)
Excel Workbook
ABCDEFGHIJKLMNO
141012123456789101112
23114102OUT40016OUT13
3352
Sheet1
 
Upvote 0
It isn't clear ..

- if there can be more (or less) than 2 OUT values in the row, but there will be at least one OUT

- if there are lots of rows like this to deal with

- if there is a maximum number of columns that the data can occupy

My suggestion below assumes ..

- there can be more/less than 2 OUT values in the row

- the are not too many of these rows to deal with as I have used the volatile OFFSET function which may adversely affect your sheet performance if too many of these formulas are used on your sheet.

- data does not go beyond column Z

- that you are using Excel 2007 or later


Formulas in column A are stand-alone
Formulas in column B are copied across as far as you might need
Row 4 is used as a helper row.

These formulas may need further tweaking depending on just what might occur in your sheet.

If this doesn't meet your needs, please give more examples of sample data and expected results.

mzi

ABCDEFGHIJKLM
1102OUT4..16OUT13
23114
3352
441026
5

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"><col style="width:41px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
A2=SUM(OFFSET(A1,0,0,1,A4))
B2=IF(B4="","",SUM(OFFSET($A1,0,A4,1,B4-A4)))
A3=COUNTA(OFFSET(A1,0,0,1,A4))-1
B3=IF(B4="","",COUNTA(OFFSET($A1,0,A4,1,B4-A4))-1+(C4=""))
A4=MATCH("OUT",A1:Z1,0)
B4=IF(COLUMNS($B4:B4)>COUNTIF($A1:$Z1,"OUT"),"",IFERROR(MATCH("OUT",INDEX($A1:$Z1,A4+1):Z1,0)+A4,COLUMNS($A1:$Z1)))

<tbody>
</tbody>

<tbody>
</tbody>


Thanx a Lot Sir, it worked perfectly for me, the results with these formulas are exactly what i want thank you so much....
 
Last edited by a moderator:
Upvote 0
Thank you Mr. Akashwani and Mr. Marcol, your formulas helped me, thanx for you suggestions...
 
Upvote 0
Thanx a Lot Sir, it worked perfectly for me, the results with these formulas are exactly what i want thank you so much....
Glad it worked for you. :)


Another suggestion.

This should handle any length of row after Column D, provided "OUT" appers twice in the row.
A couple of comments ..

- It can only be assured of handling any length row if the user is using Excel 2003 or older (though I acknowledge it may be unlikely that more columns are used anyway).

- It would fail if it is possible that OUT is the first or last item in the row

If we assume okay to use columns D:IV, exactly 2 OUT values and all other data is numerical (I interpreted the original post as having "." values in the row as well), then A2:C3 below would be an alternative approach with more straight-forward formulas, also avoiding OFFSET, and handling OUT being first/last.

If other text values are allowed in the data, then the formulas in A4:C4 could be used instead of those in A3:C3.

Excel Workbook
ABCDEFGHIJKLMNO
1410
23114102OUT40016OUT13
3352
4352
Sum and Count
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,212
Messages
6,129,533
Members
449,515
Latest member
lukaderanged

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