我完全不知道为什么我会收到"类型不匹配"错误。
错误出现在范围(RelAddy(上。配方线。
Sub CallingUserformAssignJC()
BeforeLastRow = Sheets("Information").Cells(Rows.Count, 19).End(xlUp).Row
Sheets("Information").Range("U2:U" & BeforeLastRow).ClearContents
LastRowAC = Sheets("Information").Cells(Rows.Count, 19).End(xlUp).Row
LastCol = Sheets("Today").Cells(1, Columns.Count).End(xlToLeft).Column
For j = 1 To LastCol
CurrLastRow = Sheets("Today").Cells(Rows.Count, j).End(xlUp).Row
startAddy = Sheets("Today").Cells(2, j + 1).Address
endAddy = Sheets("Today").Cells(CurrLastRow, j + 1).Address
RelAddy = Sheets("Today").Cells(CurrLastRow + 1, j + 1).Address
Range(RelAddy).Formula = "=COUNTA(" & Sheets("Today").Range(startAddy, endAddy) & ")"
unassignedMilestone = Sheets("Today").Cells(CurrLastRow + 1, j + 1).Value
Do While unassignedMilestone <> 0
frmAssignJC.Show
frmAssignJC.Hide
Loop
j = j + 3
Next j
End Sub
我看过局部变量窗口,startAddy,endAddy和RelAddy都是Variant/String类型。任何帮助将不胜感激,谢谢。
问题出在Range("B2").Formula = "=COUNTA(" & Sheets("Today").Range(startAddy, endAddy) & ")"
试试Range("B2").Formula = "=COUNTA(" & Sheets("Today").Range(startAddy, endAddy).Address & ")"
为了使用公式,您需要获取范围的地址,而不仅仅是范围