A Presumably Easy Question for the Experts

  • Thread starter Thread starter Max Power
  • Start date Start date
M

Max Power

Dear Excel Experts,

I have what should be a rather simple task. Starting with a worksheet
with several rows with multiple-column entries, I wish to create a new
worksheet (or workbook) containing a random sample from the original
sheet's full row entries. I really look forward to your suggested
solutions. My intent is to use VBA code which is already created to
make these selections as an array of valid values.

My expertise deals more with statistics so I try to help people where
I can in this regard. I look forward to learning more from this
groups' experts to put these solutions into the Excel environment.

Regards,
Max
 
This is a simple example from which to work:

Option Explicit

Sub Main()
Dim wks0 As Worksheet
Set wks0 = ActiveSheet
Dim wks1 As Worksheet
Set wks1 = Worksheets.Add

Dim i As Long
For i = 15 To 1 Step -1
If Int((Rnd() * 3) + 1) > 2 Then
wks0.Rows(i).Copy
wks1.Rows(1).Insert Shift:=xlDown
End If
Next i

Application.CutCopyMode = False
Set wks0 = Nothing
Set wks1 = Nothing

End Sub

It assumes the active sheet is the one you want to copy from, adds a sheet
every time it is run, assumes the rows to copy are 1 thru 15, and that you
want approximately a third of the rows copied on a pass.
 
Thank you, Max and Bob, for your very prompt and helpful responses.
I'll try these out to see if they'll address my application.

Best regards,
Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top