ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help on code to sample data (https://www.excelbanter.com/excel-programming/453723-help-code-sample-data.html)

redeemed

Help on code to sample data
 
I am in Excel 2010.

Working with very large data files generating samples for different managers .

I have my data in the Details tab of a spreadsheet the Managers Names are in C1 and to the end of column c & the employees Names are in D1 and scroll down...

In order to get my sample I run the sampler macro below.

In this macro I enter the n value that is the total number of the rows in the data. This data can contain data for multiple managers and their employees.

I then enter the Step value. which is give to me .
This could be like 2.5 or 23.7 or 4 or 110 it could be any number.

Issue is that I must have a sample of a minimum of two employees for each manager.

This sampler macro does not guarantee me a sample of at least two sample each for every employee Can this be fixed by modifying the code in the sampler macro below?

Thanks in advance, appreciate any enhancement of the code below as I am not a programmer.



Sub Sampler()
Source_Sheet = "Source"
Target_Sheet = "Target"


n = 2919 ' your last line of data on Sheet1
Target_Row = 1
Sheets(Target_Sheet).Select
For nCount = 1 To n Step 130 ' Enter the Sample Interval


Worksheets(Source_Sheet).Cells(nCount, 1).EntireRow.Copy
Worksheets(Target_Sheet).Cells(Target_Row, 1).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Target_Row = Target_Row + 1
Next


End Sub

Living the Dream

Help on code to sample data
 
Hi

Not sure if this will help or not, but! You could try this link which is for a random number generator.

You may be able to reconfigure it to select employees instead of numbers.

https://www.get-digital-help.com/201...tery-in-excel/

HTH
Mark.

redeemed

Help on code to sample data
 
thanks Mark


All times are GMT +1. The time now is 07:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com