Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50167

Macro to copy across data based on a cell value

$
0
0
This is going to be a really obvious solution, but I currently have the code working- but it pastes to the next available row.

I am trying to get it to paste into cell B2 and always there (so clearing the column first)...any ideas? The code is this:

Code:

Sub Copy_Parent()
Dim i As Long, x As Range
    With Sheets("Sheet1")
        For i = 2 To .Range("b" & Rows.Count).End(xlUp).Row
            If .Cells(i, "a").Value = Sheets("Sheet2").Range("H5") Then
            .Cells(i, "b").Copy
            Sheets("Sheet2").Range("b" & Rows.Count).End(xlUp)(2).PasteSpecial _
            Paste:=xlPasteValues
            End If
          Next
    End With

End Sub

Cheers

Strud

Viewing all articles
Browse latest Browse all 50167

Trending Articles