paste special values in vba

后端 未结 4 1605
太阳男子
太阳男子 2021-01-20 22:54

I am working on a small project which requires me to copy and paste certain columns if I detect \"true\" in the row. I am trying to paste these selected columns onto a diffe

4条回答
  •  旧时难觅i
    2021-01-20 23:29

    Is this what you are trying?

    Option Explicit
    
    Sub Sample()
        Dim rRange As Range
        Dim RowCount As Integer, i As Long
        Dim nysheet As Worksheet
    
        On Error Resume Next
        Application.DisplayAlerts = False
        Sheets("T1").Delete
        Application.DisplayAlerts = True
        On Error GoTo 0
    
        Set nysheet = Sheets.Add()
        nysheet.Name = "T1"
    
        With Sheets("FemImplant")
            RowCount = .Range("I" & Rows.Count).End(xlUp).Row
    
            .AutoFilterMode = False
    
            Set rRange = .Range("I2:I" & RowCount)
    
            With rRange
                .AutoFilter Field:=1, Criteria1:="True"
    
                .Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
                nysheet.Range("B1").PasteSpecial xlPasteValues
    
                .Offset(1, -7).SpecialCells(xlCellTypeVisible).Copy
                nysheet.Range("A1").PasteSpecial xlPasteValues
            End With
    
            .AutoFilterMode = False
        End With
    End Sub
    

提交回复
热议问题