Formula to count how many adjacent cells have value that precede specified cell

lisburl

New Member
Joined
Apr 7, 2018
Messages
8
Good afternoon!

I need help with a formula that will give me the total the number of cells in a row that contain a value that are adjacent to a target cell (H).

For example: Column H would total the following
<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
BCDEFGH TOTAL
0001011
1101011
0101011
0011001
0101000
0100112
0001011
0101011
0101113
0011000

<colgroup><col style="width: 100px"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"></colgroup><tbody>
</tbody>


Thank you for any help.
 
I figured out why this formula did not work for me at first. I had added an additional so my data had shifted from C to H.

It works now that I updated it to reflect the correct columns. I have run into a challenge though because occasionally the vlookups are returning empty cells. This does not affect the outcome if the last column is a 0, but if it's a 1 it is adding the blank cells as 1s. Is there any way around this?

BTW - your formula has saved me sooooo much time!! Thank you!!!
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I figured out why this formula did not work for me at first. I had added an additional so my data had shifted from C to H.

It works now that I updated it to reflect the correct columns. I have run into a challenge though because occasionally the vlookups are returning empty cells. This does not affect the outcome if the last column is a 0, but if it's a 1 it is adding the blank cells as 1s. Is there any way around this?

BTW - your formula has saved me sooooo much time!! Thank you!!!

Hi!

I'm happy that my suggestion help you.

Try the new version below:

=COLUMNS(B2:G2)-IFERROR(MATCH(2,INDEX(1/((B2:G2=0)+(B2:G2="")),)),0)

Markmzz
 
Upvote 0
New issue popped up - We are collecting data for more than six months now, and I'd like to extend the formula. So instead of B:G I need it to go from B:M. The issue is that data is uploaded at different times and the blank cells that precede the formula cell make the formula result in a 0. (If the blank cells precede cells that have a 1 or 0 the sum is not affected).

For instance:Everything works if the formula ends at G: =COLUMNS(B2:G2)-IFERROR(MATCH(2,INDEX(1/((B2:G2=0)+(B2:G2="")),)),0)
<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
BCDEFGHIJKLMN
10112

<colgroup><col style="width: 100px"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"></colgroup><tbody>
</tbody>

It doesn't work if the formulat ends at M: =COLUMNS(B2:M2)-IFERROR(MATCH(2,INDEX(1/((B2:M2=0)+(B2:M2="")),)),0)<style type="text/css"><!--td {border: 1px solid #ccc;}br {mso-data-placement:same-cell;}--></style>
11011

<colgroup><col style="width: 100px"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"><col width="100"></colgroup><tbody>
</tbody>



Any suggestions?
Thank you!!
 
Upvote 0

Forum statistics

Threads
1,216,190
Messages
6,129,422
Members
449,509
Latest member
ajbooisen

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