Solved

Extracting Every 19 Records in Excel to Create Random Sample

Posted on 2011-03-07
7
264 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now