2

我正在尝试将一系列单元格粘贴到另一个工作表中。到目前为止,这是我想出的:

For i = 1 To MyCount

    wbk.Activate

    Set Criteria = Sheets(IGMSheet).Cells(i, 1)


    Sheets(IGMSheet).Range(Cells(i, 2), Cells(i, 4)).Copy 'this copies the 3 cells I need

    w.Activate
    If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData 'remove autofilter

    Selection.AutoFilter

    Range("$A$1:$BM$204").AutoFilter Field:=2, Criteria1:=Criteria.Value

    Range("$BC$1:$BE$204").SpecialCells(xlCellTypeVisible).PasteSpecial


Next i

如果我只是更新范围内的一个值,那么它可以工作,但粘贴单元格不会。

好心劝告。

4

1 回答 1

2

Further to my comment above, try this...

Dim rng As Range

For i = 1 To MyCount
    wbk.Activate
    Set Criteria = Sheets(IGMSheet).Cells(i, 1)

    Set rng = Sheets(IGMSheet).Range(Cells(i, 2), Cells(i, 4))

    w.Activate
    If ActiveSheet.AutoFilterMode Then ActiveSheet.ShowAllData 'remove autofilter

    Selection.AutoFilter

    Range("$A$1:$BM$204").AutoFilter Field:=2, Criteria1:=Criteria.Value

    rng.Copy

    Range("$BC$1:$BE$204").SpecialCells(xlCellTypeVisible).PasteSpecial
Next i

There are few other things that I noticed. For example using .Activate and unqualified cells Range(Cells(i, 2), Cells(i, 4))

You might also want to see this

于 2013-08-08T06:58:28.003 回答