简体   繁体   中英

Copy value in column A if there is a value in column B the paste starting in E7 Excel

Looking to loop through column B and if the word 'Match" is present copy the value in column A and paste to E7 sheet1. tried this:

Private Sub Consolidate_Matches()
    Dim Match As String
    Dim FinalRow As Integer
    Dim i As Integer

    Match = Sheets("Sheet1").Range("P1").Value
    FinalRow = Sheets("Sheet1").Range("B10000").End(xlUp).Row

    For i = 2 To FinalRow
        If Cells(i, 2).Value = "Match" Then
            Range(Cells(i, -1)).Copy
            Range("e7").End(xlUp).Offset(1, 0).PasteSpecial
        End If
     Next

End Sub

Try:

Sub test()

    Dim Lastrow As Long, i As Long

    With ThisWorkbook.Worksheets("Sheet1")

        Lastrow = .Cells(.Rows.Count, "B").End(xlUp).Row

            For i = 2 To Lastrow

            If .Range("B" & i).Value = "Match" Then
                .Range("E7").Value = .Range("A" & i).Value
            End If

        Next i

    End With


End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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