在循环中设置“n = …”所需的对象

j = 2 Do While PA.Cells(j, 1) <> "" Set n = (Cells(j, 50).End(xlDown).Rows.Count) - 2 If Cells(j, 50) <> "" Then Range(Cells(j, 50), Cells(j, 145)).Select Selection.AutoFill Destination:=Range(Cells(j, 50), Cells(j + n, 145)) End If j = j + 1 Loop 

我正在收到一个对象所需的错误行“Set n = …”

我不知道如何解决这个问题。 如果“Set n =”的值需要超出循环范围,那么当每个j不同时,我怎么能改变n值呢?

在vba中 , Set命令仅用于对象,不用于基本数据types或变体。 在这种情况下, n被用作整数(或长整数),但实际上可能是一个变体。 因此, Set不是必需的,会引发错误。