我的代码应该在“L”列中自动填充 K2=J2 等的“IF”公式,但遇到运行时错误 1004。
我希望宏完成整个列,直到它到达 K 列中包含数据的最后一行。
代码:
Sub SiteAccess()
Dim mySheet As Worksheet, myOtherSheet As Worksheet, myBook As Workbook
Set myBook = Excel.ActiveWorkbook
Set mySheet = myBook.Sheets("SiteAccessReports")
Set myOtherSheet = myBook.Sheets("Sheet1")
Dim ff As Long
ff = myOtherSheet.Range("L2:L" & myOtherSheet.Cells(myOtherSheet.Rows.Count, "L").End(xlUp).Row).Count
With Sheets("Sheet1")
.Range("L2").Formula = "=IF(RC[-2]=RC[-1],""No"",""Yes"")"
Selection.AutoFill Destination:=Range("L2:L" & ff), Type:=xlFillDefault 'Error Line
End With
End Sub