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.

before cleanup

desired result requested

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

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -