仅在复制/粘贴到可见单元格时键入错配

我试图复制并粘贴到可见的单元格列表。 出于某种原因,我得到一个types错过匹配错误,我不明白为什么。 debugging时在第三行发生错误。

Sub Copy_Filtered_Cells() Set from = Sheets(Sheet2).Range("I16831:I20610") Set too = Application.InputBox("J4:J16821", Type:=8) For Each Cell In from Cell.Copy For Each thing In too If thing.EntireRow.RowHeight > 0 Then thing.PasteSpecial Set too = thing.Offset(1).Resize(too.Rows.Count) Exit For End If Next Next End Sub 

最好使用Option显式在模块顶部,我猜你正在尝试实现什么。 这是一个刺…

 Option Explicit Sub Copy_Filtered_Cells() Dim from As Excel.Range Set from = Sheets("Sheet2").Range("I16831:I20610") Dim too As Excel.Range Set too = Sheets("Sheet2").Range("J4:J16821") 'Application.InputBox("J4:J16821", Type:=8) Dim Cell As Excel.Range For Each Cell In from Cell.Copy Dim thing As Excel.Range For Each thing In too If thing.EntireRow.RowHeight > 0 Then thing.PasteSpecial Set too = thing.Offset(1).Resize(too.Rows.Count) Exit For End If Next Next End Sub