How to copy multiple rows using If

Diving_Dan

Board Regular
Joined
Oct 20, 2019
Messages
161
Hi all,

I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need to replicate this for the 19 rows beneath this. Do I need to Keep writing the same code for each row or can I write a code to cover all the rows.

Thanks


Code:
Sub Copy_To_Email()

    If Not Range("B5") = "" Then
        Range("E5:H5,N5").Copy
        
    End If
        
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi Dante,

Ross posted some code above which works. The only bug with it is that once pasted it leaves the dotted moving outline around the last data copied.

I basically want the code to look at B5 and if there is anything in that cell to copy Cells E5:H5 & N5 and to paste it into A2 on the Email sheet. Then go down each row down to B24 doing the same thing and pasting it onto the next available row within the email sheet. So anything in B6 then copy E6:H6 & N6 etc.

I hope this makes sense.

Thanks

Dan
To remove those matching ants just add this line of code near the bottom of your script:

Application.CutCopyMode = False
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,972
Members
452,540
Latest member
haasro02

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