I have a simple function that shades every other row of a given range in a worksheet:
Public Function ShadeEveryOtherRow()
Sheets("mySheet").Select
ShadedRows = Range("myRange").Rows.Count
' determines the number of rows to shade in the range
' Code that loops through and shades rows here
End Function
I would like to be able to call this function with a given worksheet name and range as inputs. If I write the function as shown below and attempt to execute using the test() sub, I get a "Compile Error: Type mismatch" error. Any assistance would be appreciated. Thanks.
Public Function ShadeEveryOtherRow(targetSheet As Worksheet, targetRange As Range)
Dim targetSheet As Worksheet
Dim targetRange As Range
Sheets(targetSheet).Select
shadeRows = Range(targetRange).Rows.Count
'Code that shades rows here
End Function
Sub test()
ShadeEveryOtherRow "mySheet", "myRange"
End Sub