Copying specific cells from rows containing certain text

Chirolove

New Member
Joined
Jul 2, 2019
Messages
19
Hello all,

I am trying to copy/paste specific cells from rows that contain the word "YES" into another worksheet.

Let me say that I am brand new to VBA and just starting to understand, but am far from mastering this art.

So far, this is what I have; it copies the cells from column D to AA, but I only really need the values from columns D and P:AA (E:O are not needed).

Is it also possible to paste these values beginning in the target sheet's column B? I need the current values from column A to stay there and not be replaced.

Thank you very much in advance for your replies! I've been trying to figure this out for a while.

Code:
Code:
Sub CopyYes()


    Dim c As Range
    Dim j As Integer
    Dim Source As Worksheet
    Dim Target As Worksheet


    Set Source = ActiveWorkbook.Worksheets("2020 Budget")
    Set Target = ActiveWorkbook.Worksheets("Shutdown 2020")


    j = 4     ' Paste starting in 4th row of target worksheet
    For Each c In Source.Range("O7:O500")
           If c = "YES" Then
           Source.Range("D" & c.Row & ":AA" & c.Row).Copy Target.Rows(j) 'Copy from cells D to AA
           j = j + 1
        End If
    Next c

End Sub
 
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
Makes sense, indeed! I'm learning gradually and posts like this help with understanding the logic that sometimes is missing when scripting, thank you for taking the time it means a lot :)

Have a nice day!
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top