Solved

Extracting Every 19 Records in Excel to Create Random Sample

Posted on 2011-03-07
7
268 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

831 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