VBA query ( Pick a random cell ) RRS feed

  • Question

  • Its regarding the picking up random (n-5) cell items from a sheet and pasting it into different sheet.

    Any idea how to pick random cell contents each time a button is clicked?

    Thursday, June 23, 2016 10:02 AM


  • Sub Test()
      Dim Values, i As Integer
      'Redim 1 to Nth items
      ReDim Values(1 To 5)
      'From this cells
      With Sheets(1).Range("C3:F12")
        'Get them
        For i = 1 To UBound(Values)
          Values(i) = .Cells(Int(.Rows.Count * Rnd) + 1, Int(.Columns.Count * Rnd) + 1)
      End With
      'Write into the other sheet
      Sheets(2).Range("A1").Resize(1, UBound(Values)) = Values
    End Sub

    Thursday, June 23, 2016 10:27 AM