VBA to move rows

BadFish523

Board Regular
Joined
Feb 15, 2018
Messages
56
Hello,

I have a sheet with a table in it. What I'm wanting to do is when the row count reaches 1750 I would like to take the top 1000 rows (not the header row) and move them to the first empty row on another sheet. I am basically trying to keep only a 1000 rows of data and then add the others to an Archive sheet. I need the rows on the data sheet that were copied over to be removed from the data sheet after they are copied over so the last rows will move up to become the new first rows of data if that makes sense?

Hope I didn't make it too confusing,
Stephen
 
I am trying to do the same thing but i get an error when code is run.
Run-time error '9'
Subscript out of range

any suggestion for me to achieve same as original poster
What is your code and which line is highlighted when you select the "debug" option?
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
What is your code and which line is highlighted when you select the "debug" option?
VBA Code:
Sub Demo1()
    
    With Sheets("Data").ListObjects(1).DataBodyRange.Rows
        If .Count >= 1750 Then
           .Item("1:1000").Copy Sheets("Archive").Cells(Rows.Count, 1).End(xlUp)(2)
           .Item("1:1000").EntireRow.Delete
        End If
    End With
End Sub

With Sheets("Data").ListObjects(1).DataBodyRange.Rows this one is highlighted
 
Upvote 0
Is your data sheet named "Data", and is the table the first object on the sheet?
What exactly is the name of your table?
Are you already on the "Data" sheet when you trying running the code?
 
Upvote 0
Is your data sheet named "Data", and is the table the first object on the sheet?
What exactly is the name of your table?
Are you already on the "Data" sheet when you trying running the code?
Well i feel a bit silly now. but these questions have helped solve the problem.
I forgot the step to have my data as a table. it was just data. after putting it in table format it worked.

Thanks for asking the right question. :)
 
Upvote 0
You are welcome!
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,427
Members
448,961
Latest member
nzskater

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