excel - VBA: Using worksheet name and/or range name as inputs to function -
i have simple function shades every other row of given range in worksheet:
public function shadeeveryotherrow() sheets("mysheet").select shadedrows = range("myrange").rows.count ' determines number of rows shade in range ' code loops through , shades rows here end function
i able call function given worksheet name , range inputs. if write function shown below , attempt execute using test() sub, "compile error: type mismatch" error. assistance appreciated. thanks.
public function shadeeveryotherrow(targetsheet worksheet, targetrange range) dim targetsheet worksheet dim targetrange range sheets(targetsheet).select shaderows = range(targetrange).rows.count 'code shades rows here end function sub test() shadeeveryotherrow "mysheet", "myrange" end sub
targetrange
, targetsheet
should of type string, instead of being passed function objects.
public function shadeeveryotherrow(targetsheet string, targetrange string) dim targetsheet worksheet dim targetrange range sheets(targetsheet).select shaderows = range(targetrange).rows.count 'code shades rows here end function sub test() shadeeveryotherrow "mysheet", "myrange" end sub
Comments
Post a Comment