簡體   English   中英

excel VBA復制僅粘貼行的列A?

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

我有這個公式在sheet4上生成結果。

但是,我只希望將sheet3的A列中匹配的條件復制到sheet4,而不是整個行。

在這種情況下,我只希望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和sheet4輸出

看起來像是您的台詞:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM