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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -