excel - VBA - how to use macro button for multiple boxes -




i new vba , macro. try explain trying create explain problem have it.

there 2 sheets in excel; 'sheet 1' , 'sheet 2'.

sheet 1 full of data. data goes column ak , there 4206 rows.

sheet 2 consist input cell box 'go' button next box. button assigned macro.

what want create?

in input cell box type 'gb' , press 'go' button. 'go' button through sheet 1 cells 'gb' in them. there 2 particular columns have 'gb' in them; 1 of them column k , 1 column l. 'go' button in 2 columns 'gb' , filter rows.

important note: don't want design macro 'gb' in column k and column l. instead want them 'gb' in column k or column l.

what did create?

i designed macro , assigned 'go' box. code put in:

option explicit  sub macro1() ' ' macro1 macro '     sheets("sheet 1").select     if activesheet.autofiltermode or activesheet.filtermode     activesheet.showalldata     end if     range("a12:am4216").advancedfilter action:=xlfilterinplace, criteriarange:= _         range("a1:ak2"), unique:=false  end sub 

what works code? , problem?

the code return rows has 'gb' in column l. great. however, looking of ways how change code return rows has 'gb' in column k or column l.

any advice on please?

thank you.

i think should it. little confused on whether 'gb' vary or if same every time, included option both (by default code assumes it's static). didn't know if wanted case-sensitive, default, not case sensitive (to make case-sensitive, remove lcase functions).

sub macro1() dim ws worksheet dim firstrow long, lastrow long dim firstcol string, secondcol string dim findstr string dim x long  'define worksheet check set ws = activeworkbook.sheets("sheet1") 'or whichever sheet  'define search string check based on static value findstr = "gb"  'define search string check based on cell value 'findstr = ws.cells("a1") 'or whichever cell  'define start , end rows loop through firstrow = 12 lastrow = 4216  'define columns check firstcol = "k" secondcol = "l"  'turn off screenupdating application.screenupdating = false  'unhide rows in range ws.range(ws.rows(firstrow).entirerow, ws.rows(lastrow).entirerow).hidden = false  'loop through rows x = firstrow lastrow     'if either cell has search string in (regardless of case)...     if instr(lcase(ws.range(firstcol & x)), lcase(findstr)) or instr(lcase(ws.range(secondcol & x)), lcase(findstr))         '...do nothing     else         '...otherwise, hide row         ws.rows(x).entirerow.hidden = true     end if next x  'turn screenupdating on application.screenupdating = true      end sub 

please note cyril mentioned above, not true filter: hides rows don't match specified criteria.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -