2014-11-25 75 views
0

我有这个公式来生成sheet4的结果。但是,我只希望将来自sheet3的列A的匹配条件复制到sheet4,而不是整个行。excel VBA复制粘贴只有列A行?

在这种情况下

,我只想36238和63545在sheet4作为输出

一直试图修改夫妇,不能工作来展示,所以只粘贴原来的代码在这里看到,如果任何人都可以针点的修改。

这里是我的全码:

Private Sub CommandButton1_Click() 

    FilterCriteria1 

End Sub 

Sub FilterCriteria1() 

Dim LSearchRow As Long 
Dim shtSearch As Worksheet 
Dim shtCopyTo As Worksheet 
Dim rw As Range 

    LSearchRow = 2 'Start search in row 2 

    Set shtSearch = Sheets("Sheet3") 
    Set shtCopyTo = Sheets("Sheet4") 

On Error GoTo Err_Execute 

    Do While Len(shtSearch.Cells(LSearchRow, 1).Value) > 0 

     Set rw = shtSearch.Rows(LSearchRow) 

     If rw.Cells(4).Value = 0 And rw.Cells(7).Value <= -0.4 Then 

      MsgBox "bingo: " & rw.Cells(4).Value & "_" & rw.Cells(7).Value 

      rw.Copy shtCopyTo.Cells(Rows.count, 1).End(xlUp).Offset(1, 0) 

     End If 
     LSearchRow = LSearchRow + 1 
    Loop 

Err_Execute: 
    If Err.Number = 0 Then MsgBox "All have been copied!" Else _ 
    MsgBox Err.Description 


End Sub 

sheet3 and sheet4 output

回答

0

它看起来是您的线路:

rw.Copy shtCopyTo.Cells(Rows.count, 1).End(xlUp).Offset(1, 0) 

我想你可能想:

Cells(rw, 1).copy shtCopyTo.Cells(Rows.count, 1).End(xlUp).Offset(1, 0) 
+0

是的,当然这是李的问题嗯:)我试过你的,但它出来错误说类型不匹配 – 2014-11-25 03:45:15

+0

也许将该行上的变量替换为LSearchRow而不是rw – 2014-11-25 03:52:13