简体   繁体   English

Excel VBA自动填充问题

[英]Excel VBA Autofill trouble

I want to autofill a formula down to the last row. 我想将公式自动填充到最后一行。 If I only choose one column it works fine but if I select a larger range containing both rows and columns the function doesn't fill the first row or the first column. 如果我仅选择一个列,则工作正常,但如果选择包含行和列的较大范围,该函数将不会填充第一行或第一列。 Anyone know why? 有人知道为什么吗?

The first code snippet works like it is supposed to: 第一个代码段的工作原理如下:

If Not Intersect(Target, Range("V1")) Is Nothing Then
    wsPlan.Range("V4").Formula = "=IFERROR(INDEX(Data!$I:$I,MATCH(VALUE(ROW()&V$2),Data!$A:$A,0)),"""")"
    Range("V4").AutoFill Destination:=Range("V4:V" & Range("E" & Rows.Count).End(xlUp).Row)
End If

The second omits column V and row 4, any ideas why? 第二个省略了第V列和第4行,有什么想法吗?

If Not Intersect(Target, Range("V1")) Is Nothing Then
    wsPlan.Range("V4").Formula = "=IFERROR(INDEX(Data!$I:$I,MATCH(VALUE(ROW()&V$2),Data!$A:$A,0)),"""")"
    Range("V4").AutoFill Destination:=Range("V4:X" & Range("E" & Rows.Count).End(xlUp).Row)
End If

Write all of the formulas at once. 一次编写所有公式。 AutoFill doesn't handle a two direction fill very well. AutoFill无法很好地处理双向填充。

If Not Intersect(Target, Range("V1")) Is Nothing Then
    with wsPlan
        'write all of the formulas into V:X
        .Range(.cells(4, "V"), .cells(.rows.count, "E").end(xlup).offset(0, 19)).Formula = _
            "=IFERROR(INDEX(Data!$I:$I, MATCH(VALUE(ROW()&V$2), Data!$A:$A, 0)), text(,))"
    end with
End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM