1

I've tried using the feedback from similar threats - but I can't seem to implement any of them in my code. I apoligize as I'm brand new to macros!

I have a spreadsheet with a pivot table, from where I wish to copy A2:J2 if K2="Create". My macro is working but is copying the entire row, can someone please help me?

Sub Create()
Dim RngColF As Range
Dim i As Range
Dim Dest As Range

Sheets("Data").Select
Set RngColF = Range("K1", Range("K" & Rows.Count).End(xlUp))

With Sheets("Open quotes")
    Set Dest = .Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End With

For Each i In RngColF
    If i.Value = "Create" Then
        i.EntireRow.Copy Dest
        Set Dest = Dest.Offset(1)
        Sheets("Open quotes").Select
    End If
Next i
End Sub
1

1 Answer 1

0

Try

Sub Create()
Dim RngColF As Range
Dim i As Range
Dim Dest As Range

Sheets("Data").Select
Set RngColF = Range("K1", Range("K" & Rows.Count).End(xlUp))

With Sheets("Open quotes")
    Set Dest = .Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End With

For Each i In RngColF
    If i.Value = "Create" Then
        range(cells(i.row,1).address,cells(i.row,10).address).copy Dest
        Set Dest = Dest.Offset(1,0)
        Sheets("Open quotes").Select
    End If
Next i
End Sub

I am not sure where data is you want to copy. if it is in Data sheet then you will have a problem as you are selecting "Open Quotes" so the second time the runs around it will copy from "open quotes". may want to address that.

EDIT: for the sake of being complete Sheets("Open quotes").Select should (and believe OP has) be moved to the end of the code

3
  • Could you mark as answered if this has answered your question
    – 99moorem
    Jul 8, 2015 at 10:54
  • Sorry 99moorem but could please advise on how I mark the question answered? Your answer solved my problem and I simply moved the selection of shet Open quotes to the very end. Thank you!
    – DanielDk
    Jul 9, 2015 at 10:58
  • to the left of my answer you should see an up and down arrow, underneath them you should see a tick greyed out, click that to mark this as the answer that answered your questions :)
    – 99moorem
    Jul 9, 2015 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.