excel - 范围上的 PasteSpecial 方法失败

标签 excel vba paste autofilter

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

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

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

请多多指教。

最佳答案

根据我上面的评论,尝试这个...

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

我还注意到了一些其他事情。例如使用 .Activate 和不合格的单元格 Range(Cells(i, 2), Cells(i, 4))

您可能还想查看this

关于excel - 范围上的 PasteSpecial 方法失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18119144/

相关文章:

delphi - 为什么抑制WM_PASTE后数据集的状态变为dsEdit?

Excel公式为依赖于其他2列(名字和姓氏)的列分配唯一值?

mysql - 如何实现非程序员对 SQL 数据库的频繁批量更新。数据库每次都应该从 Excel 导入吗?

excel - 文件格式 := 51 or 52 doesn't save file as an excel file

vba - 如何在 VBA 中引用和刷新 Excel 2016 中的查询表

r - 在 R 中将多行粘贴在一起

vba - 如何将字符串格式的单元格地址与范围一起使用?

vba - 将字符串转换为日期 VBA

vba - 计算 MS Word 中选定的行数

ios - 在 iOS 中,如何禁用粘贴到 UITextfield 或其他输入字段中?