我正在尝试将列表复制并粘贴到可见单元格中。出于某种原因,我遇到了类型错过匹配错误,我不明白为什么。调试时,第三行发生错误。
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
答案 0 :(得分:1)
最好在模块顶部使用Option Explicit,我猜你想要实现的目标。这是一个刺...
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