在A栏中,我列出了5个名字--我想在B栏中创建不同的团队,并将它们命名为Team_1、Team_2等。
这是我试过的语法..。
Function AutoFill()
Dim KCLR As Long
KCLR = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
Range("B2").Select
ActiveCell.FormulaR1C1 = "Team_1"
Selection.AutoFill Destination:=Range("B2:" & KCLR)
End Function但是,在行Selection.AutoFill Destination:=Range("B2:" & KCLR)上,我得到了一个错误
Range("B2:“& KCLR) =对象'_Global‘的方法'Range’失败
为了像我所需要的那样成功地实现AutoFill,我需要做些什么?
发布于 2017-01-18 15:25:52
Selection.AutoFill Destination:=Range("B2:" & KCLR)应该是Selection.AutoFill Destination:=Range("B2:B" & KCLR),因为KCLR正在返回一个数字。
发布于 2017-01-18 15:52:03
按照@harun24hr的答案,为了将来更好的编码实践,请避免使用Select、ActiveCell和Selection,并使用完全合格的Range。
见下面的例子:
Function AutoFill()
Dim KCLR As Long
KCLR = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
Range("B2").FormulaR1C1 = "Team_1"
Range("B2").AutoFill Destination:=Range("B2:B" & KCLR)
End Functionhttps://stackoverflow.com/questions/41723084
复制相似问题