Solved

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

Posted on 2014-09-03
122 Views
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.

Regards,

Dallag
Convert-Large-files-to-500-GA.xlsx
0
Question by:dallagmm

LVL 19

Expert Comment

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.
0

Author Comment

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.

Regards,

Dallag
0

LVL 48

Accepted Solution

Rgonzo1971 earned 500 total points
Hi,

pls try

Sub Macro1()
'
' Macro1 Macro

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

LVL 12

Expert Comment

What do you want to happen if you have 1353 rows, such as in your data?
0

Author Closing Comment

Thanks
0