I need to select only 500 rows covering any range of data (sampling)

Dear All,

I need to select only 500 rows covering any range of the input sheet  (sampling) as attached here. The rows should be selected equally to cover the data range.

I need the first row and the last row and the rows between should be equally selected and moved the output sheet.


Mohammed DallagPetroleum ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

helpfinderIT ConsultantCommented:
It is definitely possible to use some VBA macro to achieve this, but if you need only this I guess the fastest way will be manual work instead of looking for code and make .xlsb
Just press F5 in your Input sheet and type A1:B500 to select first 500 rows and copy-paste it into Output sheet.
Mohammed DallagPetroleum ConsultantAuthor Commented:
I need to select 500 rows to cover the range. For example if I have 1000 rows then I should read the first row and skip the second and read the third and skip the fourth. So at the end I will be able to get 500 rows starting from the first row to the last row.



pls try

Sub Macro1()
' Macro1 Macro

LinesToBeSelected = 500
cnt = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp)).Count
diff = cnt / LinesToBeSelected
For Idx = 1 + diff To (LinesToBeSelected - 1) * diff Step diff
    rw = Int(Idx)
    Union(Selection, Range(rw & ":" & rw)).Select
Selection.Copy Destination:=Sheets("Output").Range("A1")
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James ElliottManaging DirectorCommented:
What do you want to happen if you have 1353 rows, such as in your data?
Mohammed DallagPetroleum ConsultantAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.