简体   繁体   English

excel VBA复制仅粘贴行的列A?

[英]excel VBA copy paste only column A of the row?

I have this formula to generate result at sheet4. 我有这个公式在sheet4上生成结果。

however, I only want matched criteria from sheet3's column A to be copy over to sheet4, not the entire row. 但是,我只希望将sheet3的A列中匹配的条件复制到sheet4,而不是整个行。

in this case, i only want 36238 and 63545 to show at sheet4 as output 在这种情况下,我只希望36238和63545作为输出显示在sheet4上

Been trying couple modification and can't work, so just paste this original code here see if anyone can pin point the modification. 一直在尝试进行几次修改,因此无法正常工作,因此只需在此粘贴原始代码,看看是否有人可以指出修改内容。

here's my full code: 这是我的完整代码:

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和sheet4输出

It looks to be your line: 看起来像是您的台词:

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

I imagine you probably want: 我想您可能想要:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM