excel - Limitation in counting down loop -
i have following simple excel spreadsheet:
b c 1 10 2 =b1+a2 3 =summe(b1:b2) 4
in cell a2 counting down values inserted following macro:
sub test () sheets("sheet1").range("a2").value = sheets("sheet1").range("a2").value - 1 until sheets("sheet1").range("b3") > 0 sheets("sheet1").range("a2").value = sheets("sheet1").range("a2").value - 1 loop end sub
this works fine far. however, want limit loop in macro. should countdown numbers in cell a2 until reaches number 0. should never go below 0.
do have idea how can insert such "limit" in code?
it should never go below 0.
before writing value, check if <0
, exit do
loop.
is want?
do until sheets("sheet1").range("b3") > 0 if sheets("sheet1").range("a2").value - 1 < 0 exit sheets("sheet1").range("a2").value = sheets("sheet1").range("a2").value - 1 loop
Comments
Post a Comment