Test if range contains all positive or all negative numbers or a mix of both

lovallee

Board Regular
Joined
Jul 8, 2002
Messages
220
Hello,

I want to test if a range of cells contains all positive or all negative numbers or a mix of both.

I want to avoid using something long such as embedded IFs...

If there could be a simple formula, that would be great!

Thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try. Change A1:A7 to match your range
Code:
=IF(MIN(A1:A7)>0,"all pos",IF(MAX(A1:A7)<0,"all neg","mix"))
 
Upvote 0
Thanks Scott.
I got to that point but I was wondering if there was a way to avoid the embedded "IF"s...
 
Upvote 0
It is only two Ifs nested but you could use something like this

Code:
=VLOOKUP(SUMPRODUCT(((MIN(A1:A7)>0)*1)+((MAX(A1:A7)<0)*2)),{0,"mix";1,"all pos";2,"all neg"},2,0)

Also how should Zero be handled? both of the formulas will returned Mix if one of the numbers is zero.
 
Upvote 0
Thanks Scott.

Zeros would have been treated as positive in this case.

So far, it looks like the embedded ifs is the simplest solution!

For an instant, I thought that I could use some sort of mathematical or statistical Excel function as a proxy...(i.e. a function that returns a positive or negative or an error number when applied to inputs having different signs)... that would have been simple and handy!
 
Upvote 0
This works:
Rich (BB code):
=LOOKUP(MATCH(COUNTIF(A1:A10,">0"),{10,5,0},-1),{1,2,3},{"All pos","mix","All neg"})
Where
10 = the count of all values in the range
5 = is any number within 0 and the count of all values in the range (used 5 as the medium number in this example)

Unfortunately, you cannot use COUNT(A1:A10) as an argument within the array to replace 10, similar for 5, but avoids lots of nested IFs if that's your preference..

Or you can write your own UDF e.g.
Rich (BB code):
Public Function ReturnSignStatus(ByRef Rng As Range) As String

    Dim r   As Range
    Dim x   As Long
    
    x = Application.CountIf(Rng, ">0")
    
    Select Case x
        Case Is = 0
            ReturnSignStatus = "All neg"
        Case Is = Rng.Count
            ReturnSignStatus = "All pos"
        Case Else
            ReturnSignStatus = "Mix"
    End Select


End Function
 
Last edited:
Upvote 0
This will return -1 if any value in the range is negative. 1 if all the values are 0 or greater.
Confirm with CTRL-SHIFT-ENTER rather than just Enter.

=MIN(IF(A1:A10>=0,1,-1))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,222,613
Messages
6,167,060
Members
452,093
Latest member
JamesFromAustin

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