范围类的自动填充方法失败 - 目标字段包含源字段

时间:2018-05-24 19:43:23

标签: excel vba excel-vba

我是vba的新手,我在网上做过很多研究,但仍然无法弄清楚这一点。

Sub DailyFundRecMacro()
Dim rng As Range
Dim wks As Worksheet

 ' Prevents screen refreshing.
Application.ScreenUpdating = False

Worksheets("FIMCO Data").Activate

Set wks = Worksheets("FIMCO Data")
Set rng = wks.Range(("E1"), Range("E1").End(xlDown))

Sheets("Converter").Select
Range("E1").Select
Application.CutCopyMode = False
Selection.AutoFill Destination:=rng, Type:=xlFillDefault

'Loop all the cells in range
For Each cell In Range("E1:E398")
    If Application.WorksheetFunction.IsNA(cell) Then
        'If cell contains #N/A, then set the value to 0
        cell.Value = 0
    End If
Next

Range("B1:E1").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Trial Balance Values").Select
Range("B1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
End Sub

有问题的一行:

Selection.AutoFill Destination:=rng, Type:=xlFillDefault

当我Set rng = wks.Range(("E1"), Range("E1").End(xlDown))时,自动填充功能无效,但当我只使用Selection.AutoFill Destination:=Range(("E1"), Range("E1").End(xlDown))时,代码运行正常。

感谢任何帮助。谢谢!

0 个答案:

没有答案