Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA Excel-自动填充方法超出范围类错误_Vba_Excel - Fatal编程技术网

VBA Excel-自动填充方法超出范围类错误

VBA Excel-自动填充方法超出范围类错误,vba,excel,Vba,Excel,由于某种原因,我有自动填充方法超出范围的类错误,我找不到原因。我的代码中有很多公式,我经常使用,每次都会停止我的代码。这是我的sub的相关部分: '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"

由于某种原因,我有自动填充方法超出范围的类错误,我找不到原因。我的代码中有很多公式,我经常使用,每次都会停止我的代码。这是我的sub的相关部分:

'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目的地:=范围(“AB2”、“AB”和MLR)

Selection.AutoFill目标:=范围(“N2”、“N”和MLR)


更改以下两行:

Range("AB2").Select
Selection.AutoFill Destination:=Range("AB2", "AB" & MLR)
致:


更改以下两行:

Range("AB2").Select
Selection.AutoFill Destination:=Range("AB2", "AB" & MLR)
致: