excel - VBA Help. Delete Rows based on multiple criteria -
i looking vba clean worksheet deleting rows of data not need , keeping rows of data based on multiple criteria.
i want able keep row equals "subtotal:" in column , row contains number in column c while deleting other rows not match criteria.
i wrote function should able job done.
so can call function sub , pass column number want test (1 "a"), value test ("" blank), name of worksheet test. final argument boolean value , if true delete on matching value in criteria, if not delete on else.
function deletecol(icol integer, strcriteria string, strwsname string, bpositive boolean) dim ilastcol integer dim wsused worksheet set wsused = thisworkbook.worksheets(strwsname) ilastrow = wsused.cells(rows.count, icol).end(xlup).row = ilastrow 1 step -1 wsused.cells(i, icol) if bpositive if .value = strcriteria .entirerow.delete else if .value <> strcriteria .entirerow.delete end if end next end function
so requested above do:
sub delete() call deletecol(1, "subtotal:", "coolsheetname", false) call deletecol(3, "", "coolsheetname", true) end sub
Comments
Post a Comment