我正在Excel VBA中编写一个子文件,并且在尝试分配.Find()的结果时一直给我一个'类型不匹配'错误消息。到Range变量。我感到非常自信,我的类型是合适的,所以也许在某处有语法错误?'类型不匹配'错误与VBA中的.Find()方法
帮助将不胜感激: (线由星号前面就是引发错误)
Sub totalTiger(fCode As String, project As String, ttls() As Double)
'Set shorcuts to Worksheets
Dim this As Workbook: Set this = ThisWorkbook
Dim proj As Worksheet: Set proj = this.Worksheets(project)
'Dim req variables
Dim tRng As Range: Set tRng = proj.Range("A:A").Find(What:="Program Description") 'Establish where Staff data ends and Tiger data begins
***Dim rng As Range: Set rng = proj.Range("C:C").Find(What:=fCode, After:=tRng) 'First fCode entry***
'For each fCode entry BEFORE the Tiger data, sum the assignments by month
Do While Not rng Is Nothing And rng.row > tRng.row
'For each month
For col = 4 To 15
'Add this month's assignment to our running total
ttls(col - 4) = ttls(col - 4) + CDbl(proj.Cells(rng.row, col).Value)
Next
'Update the rng reference
Set rng = proj.Range("C:C").Find(What:=fCode, After:=rng)
Loop
End Sub
非常感谢你@genespos!我认为问题在于tRng在列A中,我正在C列中寻找fCode。我最终在找到范围列C后将tRng更新为行tRng.row – AllyB 2015-02-11 18:38:15