excel - Elseif is skipped -
i have following in excel file
+----------+-------+---------------+ | option | value | visibleoption | +----------+-------+---------------+ | option#1 | | #option5 | | option#2 | | #option6 | | option#3 | 3 | #option7 | | option#4 | 1200 | #option8 | +----------+-------+---------------+
the following function written
private sub commandbutton1_click() dim integer dim value_s string = 2 until isempty(cells(i, 1)) value_s = activesheet.cells(i, 2) if value_s <> "" debug.print "value_s not empty" elseif value_s = "1200" debug.print "value_s contains 1200" else debug.print "print rest" end if = + 1 loop end sub
right now, function returns following
print rest print rest value_s not empty value_s not empty
while should return following, since 1200 present:
print rest print rest value_s contains 1200 value_s not empty value_s not empty
it seems, elseif skipped. goes wrong here?
if statement closes after first successful if, in instance elseif if value empty, in case skip ... never call that. fix exact example, switch things around like:
if value_s == "" debug.print "print rest" elseif value_s = "1200" debug.print "value_s contains 1200" else debug.print "value_s not empty" end if
better way of doing be:
select case value_s case "" debug.print "print rest" case "1200" debug.print "value_s contains 1200" case else debug.print "value_s not empty" end select
in case can add many possibilities wish.
Comments
Post a Comment