复制已过滤单元格的列并粘贴到不同的列

时间:2018-03-06 17:13:56

标签: excel vba copy paste

我目前正在处理一个代码,用于复制CJ列的过滤结果并将其粘贴到F列中。当我尝试粘贴时,它只粘贴在未过滤的区域并删除列的其余部分。细胞。知道正确的代码吗?

With ActiveSheet
    With Intersect(.Range("CJ:CJ"), .UsedRange)
        .Resize(.Rows.Count - 1).Offset(1).SpecialCells(xlCellTypeVisible).Copy
    End With
End With
ActiveSheet.Range("F1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, 
_Operation:=xlNone, SkipBlanks:=False, Transpose:=False

谢谢!

2 个答案:

答案 0 :(得分:1)

for i = 1 to ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
    If Range("C" & i).entireRow.hidden = False then Range("F" & i).value = Range("C" & i).value
Next i

答案 1 :(得分:0)

以下是我发现的示例代码,它满足过滤后的副本&糊。

谢谢!

Sub CopyPasteFormula()
Dim Ws As Worksheet
Dim LRow As Long
Dim PasteRng As Range
Set Ws = Worksheets("Sheet1")
LRow = Ws.Range("K" & Rows.Count).End(xlUp).Row
Set PasteRng = Ws.Range("H1:H" & LRow).SpecialCells(xlCellTypeVisible)
Ws.Range("K:K").SpecialCells(xlCellTypeVisible).Copy
PasteRng.PasteSpecial xlPasteFormulas
Application.CutCopyMode = False 
End Sub