title: Excel VBA nested case function for multiple conditions
body: <p>I have a sql query and want to replicate in Excel VBA. I am having trouble using multiple case statements</p>
  
  <p>example columns</p>
  
  <pre><code>column(a) - segment_nbr
  
  column(b) - ltv 
  
  segment_nbr ltv 
  
  1   2.1526521   
  4   3.01348283  
  1   1.49385324  
  1   1.84731871  
  1   1.29541322  
  1   0.55659018  
  2   2.33690417  
  1   1.34068404  
  2   1.54078719  
  1   0.74087837  
  3   1.93278303  
  1   1.38347042  
  4   1.64194326  
  </code></pre>
  
  <p>I want to build a function that would replicate the following example nested if /case formula:</p>
  
  <pre><code>=if(and($A1=1,$B1&lt;=0.9),100.01,IF(and($A1=1,$B1&lt;=2.0),201.01,IF(and($A1=1,$B1&lt;=3.0),-23.26,IF(and($A1=2,$B1&lt;=0.9),-99.98,IF(and($A1=3,$B1&lt;=1.3),199.98, IF(and($A1=4,$B1&lt;=0.44),-32.43,IF(and($A1=4,$B1&lt;=1.6),160.9,"" )))
  </code></pre>
  
  <p>I tried the following but not working: it is not taking the segment_nb argument. </p>
  
  <p>any thoughts on how I can correct it?</p>
  
  <pre><code>Function ltv_w(segment_nbr, ltv )
  
  Select Case ltv 
      Case Is &lt;= 0.9 And segment_nbr = 1
          ltv_w = 100.01
      Case Is &lt;= 2.0 And segment_nbr = 1
          ltv_w = 201.01
      Case Is &lt;= 3.0 And segment_nbr = 1
          ltv_w = -23.26
      Case Is &lt;= 0.9 And segment_nbr = 2
          ltv_w = -99.98
      Case Is &lt;= 1.3 And segment_nbr = 3
          ltv_w = 199.98
      Case Is &lt;= 0.44 And segment_nbr = 4
          ltv_w = -32.43
      Case Is &lt;= 1.6 And segment_nbr = 4
          ltv_w = 160.9
  
  End Select
  
  End Function
  </code></pre>