paste special values in vba

后端 未结 4 1595
太阳男子
太阳男子 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条回答
  •  醉话见心
    2021-01-20 23:07

    Your copy/paste can be shortened considerably...

    ' CopyIfTrue()
    Dim Col As Range, Cell As Excel.Range, RowCount As Integer
    Dim nysheet As Worksheet, shtFI As Worksheet
    
    Set shtFI = Sheets("FemImplant")
    Set nysheet = Sheets.Add()
    nysheet.Name = "T1"
    
    RowCount = shtFI.UsedRange.Rows.Count
    Set Col = shtFI.Range("I2:I" & RowCount)
    
    Dim i As Integer
    i = 1
    
    For Each Cell In Col.Cells
         If Cell.Value = "True" Then
            Cell.Copy nysheet.Range("B" & i)
            nysheet.Range("A" & i).Value = _
                           shtFI.Cells(Cell.Row, 2).Value
            i = i + 1
        End If
    Next
    

提交回复
热议问题