VBA Excel - 自动填充方法超出范围类错误
Posted
技术标签:
【中文标题】VBA Excel - 自动填充方法超出范围类错误【英文标题】:VBA Excel - Autofill Method Out of Range Class Error 【发布时间】:2017-11-12 07:17:52 【问题描述】:由于某种原因,我的自动填充方法超出范围类错误,我找不到原因。我的代码中有很多公式,我经常使用它,它每次都会停止我的代码。这是我的潜艇的相关部分:
'U means union, M means main
'Advanced filter for visual worksheet
UnionWB.Worksheets("Union").ShowAllData
Dim ULR As Long, ULC As Long, MLR As Long
ULR = Cells(Rows.Count, "A").End(xlUp).Row
ULC = Cells(1, Columns.Count).End(xlToLeft).Column
With MainWB.Worksheets(sheet1)
MLR = .Cells(Rows.Count, "A").End(xlUp).Row
End With
MainWB.Worksheets("aheet2").Columns("A:Z").Clear
UnionWB.Worksheets("Union").Range(Cells(1, 1), Cells(ULR, ULC)).AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=MainWB.Worksheets("sheet1").Range("A1", "A" & MLR), Unique:=False
UnionWB.Worksheets("Union").Activate
Range("A1", "Y" & ULR).Select
Selection.Copy
MainWB.Worksheets("sheet2").Activate
Range("A1").PasteSpecial xlPasteValues
Range("AB2").Select
Selection.AutoFill Destination:=Range("AB2", "AB" & MLR)
If MLR > 2 Then
With MainWB.Worksheets("sheet1).Range("N2")
ActiveCell.FormulaR1C1 = _
"=IF(ISNUMBER(SEARCH(""sheet2"",RC[-9])),""yes"",""no"")"
Selection.AutoFill Destination:=Range("N2", "N" & MLR)
End With
End If
Selection.AutoFill Destination:=Range("AB2", "AB" & MLR)
Selection.AutoFill Destination:=Range("N2", "N" & MLR)
【问题讨论】:
【参考方案1】:更改以下两行:
Range("AB2").Select
Selection.AutoFill Destination:=Range("AB2", "AB" & MLR)
收件人:
Range("AB2").AutoFill Destination:=Range("AB2:AB" & MLR), Type:=xlFillDefault
【讨论】:
以上是关于VBA Excel - 自动填充方法超出范围类错误的主要内容,如果未能解决你的问题,请参考以下文章