Problem with formula involving IF and OFFSET

TomCon

Active Member
Joined
Mar 31, 2011
Messages
373
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Enter the following.
A1=0, B1=0
A2=0, B2=0
A3=2
Then, enter this formula into A4.
=COUNT(IF(OFFSET(A1,0,0,A3,1)>0,IF(OFFSET(B1,0,0,A3,1)>0,OFFSET(A1,0,0,A3,1))))

As specified, the formula in A4 will correctly return the result, 0.
Now change the value in A3 to 1.

Now suddenly the formula result value in A4 is not correct, the result will be 1 (not the correct answer, 0)

In fact, when the range is 1 cell, you always get 1 as the COUNT answer, even though the logical evaluates to False.
With any value >1, the formula works correctly and will give the correct count of the cells that meet the logical criteria, whatever that criteria is.

Is there any way to make this formula work for the case that the range turns out to be of length 1, as well as for all other lengths?

In a complex spreadsheet in which the equivalent of the value in A3, above, might be 1 or might be a number >1, it does create a problem if the formula returns the wrong result in the single case where the value A3 is 1, but the correct result in all other cases.

Thanks!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Is it because when a zero is entered the result is false, as you have no value for false then it will use false or 0, as 0 is a number it will count as 1.

Try this, by using "" for the false value it won't count as a number.
=COUNT(IF(OFFSET(A1,0,0,A3,1)>0,IF(OFFSET(B1,0,0,A3,1)>0,OFFSET(A1,0,0,A3,1)),""))
 
Upvote 0
From the help file

  • Logical values and text representations of numbers that you type directly into the list of arguments are counted.
  • Arguments that are error values or text that cannot be translated into numbers are not counted.
  • If an argument is an array or reference, only numbers in that array or reference are counted. Empty cells, logical values, text, or error values in the array or reference are not counted.
Because you have left the FALSE arguments of your IF's empty, the resulting logical value is counted when it is a single cell, multiple cells come under array or reference.

To fix it you simply need to add something to the FALSE arguments that will not be counted, a nullstring for example

=COUNT(IF(OFFSET(A1,0,0,A3,1)>0,IF(OFFSET(B1,0,0,A3,1)>0,OFFSET(A1,0,0,A3,1),""),""))
 
Upvote 0
From the help file

  • Logical values and text representations of numbers that you type directly into the list of arguments are counted.
  • Arguments that are error values or text that cannot be translated into numbers are not counted.
  • If an argument is an array or reference, only numbers in that array or reference are counted. Empty cells, logical values, text, or error values in the array or reference are not counted.
Because you have left the FALSE arguments of your IF's empty, the resulting logical value is counted when it is a single cell, multiple cells come under array or reference.

To fix it you simply need to add something to the FALSE arguments that will not be counted, a nullstring for example

=COUNT(IF(OFFSET(A1,0,0,A3,1)>0,IF(OFFSET(B1,0,0,A3,1)>0,OFFSET(A1,0,0,A3,1),""),""))
Wow thanks, that solves the problem as does gaz_chops reply as well. Can always count on this board for great diagnosis! Thanks again. Did they do away with "this is the solution" button? I just "liked" both of the posts above!
 
Upvote 0
You're welcome, don't remember a "solution" button, but defo isn't one now.
 
Upvote 0

Forum statistics

Threads
1,214,840
Messages
6,121,895
Members
449,058
Latest member
Guy Boot

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