Results 1 to 24 of 24

Select Random Rows and Display on new sheet

Threaded View

matt4003 Select Random Rows and... 03-30-2009, 03:42 PM
rylo Re: Select Random Rows and... 03-30-2009, 06:02 PM
matt4003 Re: Select Random Rows and... 03-30-2009, 07:40 PM
rylo Re: Select Random Rows and... 03-31-2009, 02:25 AM
matt4003 Re: Select Random Rows and... 03-31-2009, 10:36 AM
arlu1201 Re: Select Random Rows and... 02-27-2013, 06:54 AM
  1. #1
    Forum Contributor
    Join Date
    05-18-2004
    Location
    Portland, Oregon
    MS-Off Ver
    2016
    Posts
    182

    Select Random Rows and Display on new sheet

    Hello Everyone,

    I have been searching and finally found something close to what I would like to do prior to asking you all. In post: http://www.excelforum.com/excel-prog...selection.html they did an excellent job selecting the random rows.

    I need to take it one step further, I need the selected rows to be displayed on a new sheet. The idea being that I have a quiz with hundreds of questions and I only want a random selection to appear when I execute the macro. I plan on hiding the original questions and only displaying the randomly selected ones.

    Thanks for your help in advance!

    Here is the original code from the previous post.

    Sub Random()
    
      Dim arr As Variant
      Dim nodupes As New Collection
      Dim rng As Range
      
      
      
      strr = "How many to select"
      Do
        noofcells = Application.InputBox(strr, Type:=1)
        If noofcells > Selection.Cells.Count Then strr = "You must select a number less than " & Selection.Cells.Count + 1 & ".  How many to select?"
        
      Loop Until noofcells <= Selection.Cells.Count
      ReDim arr(noofcells)
      
      
      Do
        On Error Resume Next
        arr = Evaluate("=randbetween(1," & Selection.Cells.Count & ")")
        nodupes.Add Item:=arr, Key:=CStr(arr)
        On Error GoTo 0
      Loop Until nodupes.Count = noofcells
      
     If noofcells = 1 Then
       Selection.Cells(nodupes(i)).Select
      Else
        Set rng = Selection.Cells(nodupes(1))
        For i = 2 To noofcells
          Set rng = Union(rng, Selection.Cells(nodupes(i)))
        Next i
      End If
        
     rng.Select
         
      
      With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
            .PatternTintAndShade = 0
      End With
      
    End Sub
    Last edited by matt4003; 04-01-2009 at 07:10 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1