VBA仅粘贴到可见细胞

时间:2017-05-18 07:59:52

标签: excel vba excel-vba

我在Sheet2 F2:F41上有一系列单元格,我想将它们粘贴到Sheet1中的可见单元格中。 Sheet1上的可见单元格位于范围M111:M643中。我的问题是,Excel将其粘贴到我想要的另一个单元格。

它的代码段:

我是否会错过循环或类似的东西?

Sheets("Tabelle2").Select 
Dim tgt As Worksheet
Set tgt = ThisWorkbook.Sheets("Tabelle1") 
Dim from As Range 
Dim destination As Range 
Set from = Sheets("Tabelle2").Range("F2:F41") Selection.Copy   
Set destination = Sheets("Tabelle1").Range("M11:M643").SpecialCells(xlCellTypeVisible) from.Copy Destination:=Sheets("Tabelle1").Range("M111")

1 个答案:

答案 0 :(得分:-1)

请尝试此代码。

Sub copythis(ByRef rFrom As Range, ByRef rTo As Range)
    Dim rVisible As Range
    Set rVisible = rFrom.SpecialCells(xlCellTypeVisible)
    rVisible.Copy destination:=rTo
End Sub

应该被称为:

Sub caller()
    copythis "range with hidden to be copied", "range to receive"
End Sub