Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Extracting Every 19 Records in Excel to Create Random Sample

Posted on 2011-03-07
7
Medium Priority
?
276 Views
Last Modified: 2012-06-21
Hi,

I'd like to take my spreadsheet and extract every 19 records starting with record 1069 to create a random sample.  Should I create a macro or function to tell Excel to select every 19 records?

Please see attached worksheet.

Thanks,
carlynne
--S1-Select.xlsx
0
Comment
Question by:Carlynne
  • 4
  • 3
7 Comments
 
LVL 10

Expert Comment

by:Makrini
ID: 35065787
The file you attached appears to be corrupted (and has 0 bytes)

Simply run a Macro to copy every 19th row

for i = 1 to 64000 step 19
   Rows(i).copy
Next i

Open in new window

0
 

Author Comment

by:Carlynne
ID: 35065823
Hi,

Thanks very much for your reply.

I am not sure how to insert a macro. The code should also start at record 1069.

I'd really appreciate further assistance if possible.  Here's the sheet again.

Thanks so much!

Carlynne


Data-Sample.xlsx
0
 
LVL 10

Expert Comment

by:Makrini
ID: 35065864
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Carlynne
ID: 35065913
Hi there,

Thanks so much for your quick reply.  The code does select the correct first record 1069 but it only selects 135 households. I need a sample size of 192.

Also, I have to run a simple coding on 8 more spreadsheets, so I need to be able to insert the macro. I can insert a Marco. I just need to be able to see the code in a separate worksheet.

Thanks so much! You're a star!

Carlynne
0
 
LVL 10

Accepted Solution

by:
Makrini earned 2000 total points
ID: 35065949
From 1069 to 3615 (the provided data) = 2546 records

Divide that by 19 and you have 35....  You could try with 18

The code is below... - to use press alt-f11 (to open VBA).  Use insert from the menu and insert a module..

In Module 1 paste the below.

To do it on different sheets change "Sheet1" and "Sheet2" to the sheets you want to do it on

To change sample size, change the "For i = 1069 To lastrow Step 19
" to step 18 or whatever
Sub tester()
lastrow = Sheets("Sheet1").Range("A64000").End(xlUp).Row
u = 1
Application.ScreenUpdating = False
For i = 1069 To lastrow Step 19
   Rows(i).Copy
   Sheets("Sheet2").Rows(u).PasteSpecial
   Application.CutCopyMode = False
   u = u + 1
Next i
Application.ScreenUpdating = True

End Sub

Open in new window

0
 

Author Comment

by:Carlynne
ID: 35066028
Hi,

Ah, yeah, that makes sense.  

I really appreciate your help. I will try this and let you know if it works:)

carlynne
0
 

Author Closing Comment

by:Carlynne
ID: 35069338
thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question