Modification and union of both codes

Aretradeser

Board Regular
Joined
Jan 16, 2013
Messages
176
Office Version
  1. 2013
Platform
  1. Windows
Regarding these two macros, I need:
1. That in the extraction of the 5 records, do not include the title of the column.
2. Join both codes.
Thank you very much
CÓDIGO 1
Rich (BB code):
Sub RegistrosAleatorios1()
  Dim arr As Variant
  Dim i As Long, x As Long, y As Long, n As Long
  '
  n = Sheets("Hoja3").Range("C" & Rows.Count).End(3).Row
  Randomize
  arr = Evaluate("=row(1:" & n & ")")
  '
  For i = 1 To n
    x = Int(UBound(arr) * Rnd + 1)
    y = arr(x, 1)
    arr(x, 1) = arr(i, 1)
    arr(i, 1) = y
  Next
  '
  For i = 1 To 5
    Sheets("Hoja1").Range("C11").Offset(0, i - 1).Value = Sheets("Hoja3").Range("C" & arr(i, 1))
  Next
End Sub
CÓDIGO 2
Rich (BB code):
Sub RegistrosAleatorios2()
  Dim arr As Variant
  Dim i As Long, x As Long, y As Long, n As Long
  '
  n = Sheets("Hoja5").Range("C" & Rows.Count).End(3).Row
  Randomize
  arr = Evaluate("=row(1:" & n & ")")
  '
  For i = 1 To n
    x = Int(UBound(arr) * Rnd + 1)
    y = arr(x, 1)
    arr(x, 1) = arr(i, 1)
    arr(i, 1) = y
  Next
  '
  For i = 1 To 5
    Sheets("Hoja1").Range("C16").Offset(0, i - 1).Value = Sheets("Hoja5").Range("C" & arr(i, 1))
  Next
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi Aretradeser:

1. That in the extraction of the 5 records, do not include the title of the column.
2. Join both codes.

I'll remove the column titles

I put the code for the 2 requests.
You can leave your titles.

VBA Code:
Sub RegistrosAleatorios()
  Dim arr As Variant, shs As Variant
  Dim i As Long, j As Long, x As Long, y As Long, n As Long
  '
  shs = Array("Hoja3", "C11", 5, "Hoja5", "C16", 6)
  For j = 0 To UBound(shs) Step 3
    n = Sheets(shs(j)).Range("C" & Rows.Count).End(3).Row
    Randomize
    arr = Evaluate("=row(2:" & n & ")")
    '
    For i = 1 To n - 1
      x = Int(UBound(arr) * Rnd + 1)
      y = arr(x, 1)
      arr(x, 1) = arr(i, 1)
      arr(i, 1) = y
    Next i
    '
    For i = 1 To shs(j + 2)
      Sheets("Hoja1").Range(shs(j + 1)).Offset(0, i - 1).Value = Sheets(shs(j)).Range("C" & arr(i, 1))
    Next i
  Next j
End Sub

You forgot to put the feedback in the question where I gave you the code:
 
Upvote 0
You forgot to put the feedback in the question where I gave you the code:
The website did not let me answer your question.
Nor did it let me ask for more information.
I don't know why.
It didn't even let me write to you to thank you for your work.
I don't know what the problem with the web is
I also did not want to ask the question anonymously.
I would like to take this opportunity to thank you for your extraordinary work.
Thank you very much, Dante Amor
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,664
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top