Excel VBA - Delete rows on multiple values from a single column filter -


i have written code deletes rows based on single input value single column filter, want edit handle multiple input values same column filter.

the database's header on a4:z.

option explicit  sub test()      dim ws worksheet     dim lastrow long     dim rng range     dim myvalue variant     'set sheet reference     set ws = activesheet      'turn off autofilter     ws.autofiltermode = false      'get last row     lastrow = ws.cells(ws.rows.count, "a").end(xlup).row      'set range filter     set rng = ws.range("a4:z" & lastrow)      'get user input     myvalue = inputbox("periods delete?")      'set filter     rng.autofilter field:=8, criteria1:=myvalue      'delete visible rows     rng.offset(1, 0).specialcells(xlcelltypevisible).entirerow.delete      'show remaining rows removing autofilter     ws.autofiltermode = false  end sub 

the input box takes single period (month number) @ present. want take multiple values '2,3,4'. delete 2 (feb), 3 (march), 4 (april).

really not sure next, i'm still newb vba.

try replacing autofilter line this. assumes values entered in input box separated commas. converts them array.

rng.autofilter field:=8, criteria1:=array(split(myvalue, ",")), operator:=xlfiltervalues 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -