Excel VBA copy paste subsequent rows

Raptor776

New Member
Joined
Aug 29, 2014
Messages
46
Hello,

Say I have the following table, where whenever a value between certain numbers appear it copies and pastes the subsequent five rows including itself, totaling 6 rows copied. For example, if column c has a value between 0.3 to 0.4. It would copy and paste the next 5 rows to a different spreadsheet.

NameLocationValue
ABCCalifornia0.2
DEFNew York0.36
GHIFlorida0.1
JKLTexas0.6
MNOOhio0.29
PQRArizona0.84
STUNebraska0.38

<tbody>
</tbody>

This is a small sample size, however I would want it to be continuous so if when it sees 0.38 in the last row it would repeat the copy paste progress of the next 5 rows including itself. And this will essentially populate the subsequent sheet.

Thank you very much!
 
Last edited:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
First Copy your Header from Sheet1 to Sheet2 (Range(A1:C1))
then from Sheet1 run this Macro

Code:
Sub Doit()
Dim Rng As Range
Application.ScreenUpdating = False
Range("C2").Select
r = 2
Do Until ActiveCell = ""
If ActiveCell.Value >= 0.3 And ActiveCell <= 0.4 Then
Set Rng = Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row + 5, 3))
    Rng.Copy _
    Worksheets("Sheet2").Cells(r, 1)
r = r + 6
ActiveCell.Offset(1).Select
Else
ActiveCell.Offset(1).Select
End If
Loop
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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