excel - Hiding Rows if Cell in a Column Contains Certain Text or Autofiltering a Single Field with 4 Criteria -


i have sheet columns through m, containing table including rows , columns. if, in column e, cell contains string(s) "drive", "inactivity", or "halt" want row hidden. if, in column e, cell not contain string "uf_", want hidden.

i have tried several things , have looked in many places. here code have tried:

try 1 (takes wayyyy long):

with activesheet loopct = 2  while loopct < count1     doevents     application.statusbar = "making table " & loopct     txtrmv1 = "drive"     txtrmv2 = "inactivity"     txtrmv3 = "halt"     txtkp = "uf_"      celltxt = .range("e" & loopct).value      if instr(1, celltxt, txtrmv1, vbtextcompare)         .range("e" & loopct).entirerow.hidden = true     end if     if instr(1, celltxt, txtrmv2, vbtextcompare)         .range("e" & loopct).entirerow.hidden = true     end if     if instr(1, celltxt, txtrmv3, vbtextcompare)         .range("e" & loopct).entirerow.hidden = true     end if     if instr(1, celltxt, txtkp, vbtextcompare)         .range("e" & loopct).entirerow.hidden = false     else         .range("e" & loopct).entirerow.hidden = true     end if      loopct = loopct + 1 wend  end 

try 2 (runs accomplishes nothing):

private sub hidedrive(byval count1 long)     dim ws worksheet     dim rng range, acell range, bcell range      set ws = activeworkbook.sheets("sheet1")      ws         set rng = .range("e2:e" & cstr(count1))          set acell = rng.find(what:="drive", lookin:=xlvalues, _                     lookat:=xlpart, searchorder:=xlbyrows, searchdirection:=xlnext, _                     matchcase:=true, searchformat:=false)          if not acell nothing             set bcell = acell                             acell.entirerow.hidden = true                 set acell = rng.findnext(after:=acell)              loop while acell nothing , acell.address <> bcell         end if     end end sub 

here using when had 1 criteria check (obviously sitation has changed):

activeworkbook.activesheet.listobjects(tblnm).range.autofilter field:=5, criteria1:= "=*uf_*" 

what can accomplish want? haven't been able autofilter work more 2 criteria. please let me know!

i couldn't debug , run other answer given, continued working , solved myself.

instead of trying hide each word didn't want together, hid them individually , called hidden row deleting function each time.

        activesheet.listobjects.add(xlsrcrange, range(dataarea1), , xlyes).name = _             tblnm          'insert if statement here change filters based upon area         activeworkbook.activesheet.listobjects(tblnm).range.autofilter field:=5, criteria1:="=*uf_*"          call rhidrow2(count4)          activesheet.listobjects(tblnm).range.autofilter field:=5, criteria1:="<>*drive*"          call rhidrow2(count4)          activesheet.listobjects(tblnm).range.autofilter field:=5, criteria1:="<>*inactivity*"          call rhidrow2(count4)          activesheet.listobjects(tblnm).range.autofilter field:=5, criteria1:="<>*halt*"          call rhidrow2(count4)          activesheet.listobjects(tblnm).range.autofilter field:=8, criteria1:="<>#value!"          call rhidrow2(count4) 

here hidden row deleter:

private sub rhidrow2(byval count4 long)     dim count1 long 'counters used     dim ws worksheet     dim rngvis range     dim rngdel range     set ws = activesheet      on error resume next     set rngvis = ws.range("a2:a" & count4).specialcells(xlcelltypevisible)     on error goto 0      if rngvis nothing         ws.range("z1").value = 1     else          count1 = count4 2 step -1             if ws.rows(count1).hidden = true                 if rngdel nothing                     set rngdel = ws.rows(count1)                 else                     set rngdel = union(rngdel, ws.rows(count1))                 end if             end if         next count1      if not rngdel nothing         application.displayalerts = false         intersect(rngdel, rngdel.listobject.databodyrange).delete 'if row hidden, delete         application.displayalerts = true     end if      end if end sub 

this works better , faster else had tried or suggested.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -