我的代码应该自动填充K2 = J2的“IF”公式,依此类推在“L”列中,但遇到运行时错误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
答案 0 :(得分:0)
我确信有一个更好的答案,但是到目前为止还缺少任何其他答案:
Sub SiteAccess()
Dim myBook As Workbook
Dim myOtherSheet As Worksheet
Dim ff As Long
Set myBook = Excel.ActiveWorkbook
Set myOtherSheet = myBook.Sheets("Sheet1")
ff = myOtherSheet.Range("K1:K" & myOtherSheet.Cells(myOtherSheet.Rows.Count, "K") _
.End(xlUp).Row).Count
With Sheets("Sheet1")
.Range("L2").Select
.Range("L2").Formula = "=IF(RC[-2]=RC[-1],""No"",""Yes"")"
Selection.AutoFill Destination:=Range("L2:L" & ff), Type:=xlFillDefault
End With
End Sub