我有一个简单的函数,可以在工作表中对给定范围的每一行进行着色:
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
我希望能够使用给定的工作表名称和范围作为输入来调用此函数。如果我编写如下所示的函数并尝试使用 test() 子程序执行,则会收到“编译错误:类型不匹配”错误。任何援助将不胜感激。谢谢。
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