我正在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