excel - How to redefine last row within a loop -
the following code inserts rows when blank cell in col b encountered , specific values present in col a. inserted rows populated values arrays depending on condition. each time rows inserted need last row value change, code can evaluate next blank cell in col b can’t figure out how redefine last row. how make work?
- what kind of loop need use?
- where redefine last row?
- how move next blank cell in column b?
thank much,
sub missingvalues() dim zarr variant dim yarr variant dim lastrow long dim sht worksheet dim long set sht = thisworkbook.worksheets("qc") application.enableevents = false application.screenupdating = false yarr = array(array("hd300 removed alt", "egfr", "", "", "l861q", "5"), _ array("hd300 removed alt", "egfr", "", "", "kelre745delinsk", "5"), _ array("hd300 removed alt", "egfr", "", "", "l858r", "5"), _ array("hd300 removed alt", "egfr", "", "", "t790m", "5"), _ array("hd300 removed alt", "egfr", "", "", "g719s", "5")) zarr = array(array("hd200 removed alt", "braf", "", "", "v600e", "10.5"), _ array("hd200 removed alt", "kit", "", "", "d816v", "10"), _ array("hd200 removed alt", "egfr", "", "", "kelre745delinsk", "2"), _ array("hd200 removed alt", "egfr", "", "", "l858r", "3"), _ array("hd200 removed alt", "egfr", "", "", "t790m", "1"), _ array("hd200 removed alt", "egfr", "", "", "g719s", "24.5"), _ array("hd200 removed alt", "kras", "", "", "g13d", "15"), _ array("hd200 removed alt", "kras", "", "", "g12d", "6"), _ array("hd200 removed alt", "nras", "", "", "q61k", "12.5"), _ array("hd200 removed alt", "pik3ca", "", "", "h1047r", "17.5"), _ array("hd200 removed alt", "pik3ca", "", "", "e545k", "9")) lastrow = sht.cells(sht.rows.count, "a").end(xlup).row = 3 while <= lastrow debug.print debug.print lastrow if isempty(cells(i, 2).value) = true cells(i, 2).value = "header" if instr(1, cells(i, 1).value, "hd200", 1) > 0 rows(i & ":" & + 10).insert shift:=xldown 'insert 11 rows worksheets("qc").range("a" & & ":f" & + 11).value _ = application.index(zarr, 0) 'recalculate lastrow = + 12 lastrow = sht.cells(sht.rows.count, "a").end(xlup).row elseif instr(1, cells(i, 1).value, "hd300", 1) > 0 rows(i & ":" & + 4).insert shift:=xldown 'insert 5 rows worksheets("qc").range("a" & & ":f" & + 5).value _ = application.index(yarr, 0) = + 6 'recalculate lastrow lastrow = sht.cells(sht.rows.count, "a").end(xlup).row else = + 1 end if 'lastrow = sht.cells(sht.rows.count, "a").end(xlup).row end if 'lastrow = sht.cells(sht.rows.count, "a").end(xlup).row loop application.enableevents = true application.screenupdating = true end sub
whenever insert or delete lines in excel worksheet have last line.
for = lastrow 3 step -1 'your code goes here... next
Comments
Post a Comment