Function for minimum non-zero with multiple additional conditions
Try to use meaningful names. What's names (SelValue, ValOne,...) stands for? It don't give info on their purpose or usage.

Furthermore, you can simplify a lot your conditional branchments, using only this:

If ValOne &lt; 0 Or ValTwo &lt; 0 Then
    SelValue = -1
' remove this following condition to discard case 4
Else If ValOne = 0 Or ValTwo = 0 Then
    SelValue = ValOne + ValTwo  
ElseIf ValOne &gt; ValTwo &lt;&gt; NeedMax Then  
    SelValue = ValTwo
Else
    SelValue = ValOne
End If


not fully tested, but should do the trick

Edit : fixed case (4), where NeedMax is false and one of values is 0.