vba - Excel Macro - Remove rows and then relabel a cell value -
what i'm trying remove rows cell value in specific column matches defined remove. after done re-sequence value in column group.
using example below:
want @ column b , remove rows have value of or c. want renumber after dot (.) in column reset itself.
before macro code fig. 1
after value , c removed fig. 2
final list after column renumbered fig. 3
i figured out how remove rows using code, stuck on next:
sub deleterowbasedoncriteriga() dim rowtotest long rowtotest = cells(rows.count, 2).end(xlup).row 2 step -1 cells(rowtotest, 2) if .value = "a" or .value = "c" _ _ rows(rowtotest).entirerow.delete end next rowtotest end sub
this easier looping top down (using step 1 instead of step -1). i've tried stay true original coding , made this:
sub deleterowbasedoncriteriga() dim rowtotest long dim startrow long dim integer startrow = 2 'clear rows have "a" or "c" in column b rowtotest = cells(rows.count, 1).end(xlup).row startrow step -1 cells(rowtotest, 2) if .value = "a" or .value = "c" _ _ rows(rowtotest).entirerow.delete end next rowtotest 'if left 3 characters of cell above same,_ 'then increment renumbering scheme rowtotest = startrow cells(rows.count, 1).end(xlup).row if left(cells(rowtotest, 1).value, instr(1, cells(rowtotest, 1), "\")) = left(cells(rowtotest, 1).offset(-1, 0).value, instr(1, cells(rowtotest, 1), "\")) = + 1 cells(rowtotest, 1).value = left(cells(rowtotest, 1).value, instr(1, cells(rowtotest, 1), ".")) & else = 0 cells(rowtotest, 1).value = left(cells(rowtotest, 1).value, instr(1, cells(rowtotest, 1), ".")) & end if next rowtotest end sub
edit: i've updated compare of string before backslash , compare using that. edit++: has been brought attention when deleting rows better work bottom (step -1) ensure every row accounted for. i've re-implemented original steps in first code.
wiki
Comments
Post a Comment