Calling Generic sub in Excel with changes to variables in string, long an range format -
i have following code must filter range of material data according specified item (if item in short description must filter) , copy new spreadsheet. should done multiple times , efficient, have generic sub , call when need (and change item specific variables). generic code follow:
sub generic_item_quantity(byval new_sheet string, byval item string, byval rngcurrent range, byval lastcellcurrent long) 'add item sheet current month , copy data, if exists, delete on error resume next sheets(new_sheet).delete on error goto 0 worksheets.add activesheet.name = new_sheet ' filter item in current material sheet sheets("materials current").select lastcellcurrent = sheets("materials current").cells(sheets("materials current").rows.count, "a").end(xlup).row - 1 set rngcurrent = sheets("materials current").range("a1:c" & lastcellcurrent + 1) filterfield = worksheetfunction.match("short description", rngcurrent.rows(1), 0) 'turn on filter if not turned on if activesheet.autofiltermode = false rngcurrent.autofilter 'filter item rngcurrent.autofilter field:=filterfield, criteria1:=array( _ "=*item*"), operator:=xlfiltervalues ' select filtered range , copy new sheet sheets("materials current").range("a1:c1").select range(selection, selection.end(xldown)).select selection.copy sheets(new_sheet).select range("a1").select selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false and later in code want call sub multiple times different variables stated above. calling code follows (this code item called knife, other handle etc.):
generic_item_quantity "knife current", "knife", rngknifecurrent, lastcellknifecurrent however, error code stating compile error: type mismatch. please note code on own (when make item specific) works perfectly, generic code gives problems.please assist
Comments
Post a Comment