复制整行而不是只复制一个字段

时间:2015-11-12 16:12:59

标签: excel-vba vba excel

有人可以告知我的编码有什么问题。它仅通过一个字段,即列'A'而不是整行。我想复制选择的行和过去的其他文件..

Dim LastRow As Long
Dim rlastrow As Long
Dim rr As Range

Dim myFileNameDir1 As String
Dim zz As Integer
Dim Irow As Range

myFileNameDir1 = Sheet3.Range("V7").Value
Workbooks.Open fileName:=myFileNameDir1, UpdateLinks:=0
Set ws2 = Worksheets("Tracker")
str = ListView6.SelectedItem
Set match = ws1.Cells.Find(str)
LastRow = ws2.UsedRange.Rows.Count


With ws1
     .AutoFilterMode = False
     IRow1 = .Range("A" & .Rows.Count).End(xlUp).Row
     With .Range("A1:A" & IRow1)
          .AutoFilter Field:=1, Criteria1:=str
          .Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Destination:=ws2.Range("A" & LastRow + 1)

     End With
    .AutoFilterMode = False

End With

1 个答案:

答案 0 :(得分:0)

更改行:

.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Destination:=ws2.Range("A" & LastRow + 1)

.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Copy Destination:=ws2.Range("A" & LastRow + 1)