Hi fatboyzfishing,
Welcome to the forum!!
Let me know how this goes:
Option Explicit
Sub Macro1()
Dim ws As Worksheet
Dim lngEndRow As Long
Dim lngLoopCount As Long
Dim objRowNumbers As Object
Dim lngMyRow As Long
Application.ScreenUpdating = False
Set ws = Worksheets("Key List")
lngEndRow = ws.Cells(Rows.Count, "A").End(xlUp).Row 'Sets the 'lngEndRow' variable from Col. A of the ws tab. Change to suit.
Set objRowNumbers = CreateObject("Scripting.Dictionary")
Randomize 'Without this the output will be the same
Do Until lngLoopCount = Int(lngEndRow / 4) 'Rounds down to the nearest integer ie for 26 items it will run 6 times.
lngMyRow = Rnd * (lngEndRow - 1) + 1
If lngMyRow > 0 Then
If objRowNumbers.Exists(CStr(lngMyRow)) = False Then
If InStr(ws.Name, " ") > 0 Then 'Tabs with a space(s) need to be incased within single quotes
With Sheets("Random List").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Formula = "='" & CStr(ws.Name) & "'!A" & lngMyRow
.Value = .Value 'Converts the formula from the line above to a value. Comment out to leave original formula as is.
End With
Else
With Sheets("Random List").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
.Formula = "=" & CStr(ws.Name) & "!A" & lngMyRow
.Value = .Value 'Converts the formula from the line above to a value. Comment out to leave original formula as is.
End With
End If
objRowNumbers.Add CStr(lngMyRow), lngLoopCount
lngLoopCount = lngLoopCount + 1
End If
End If
Loop
Set ws = Nothing
Set objRowNumbers = Nothing
Application.ScreenUpdating = True
End Sub
Regards,
Robert
Bookmarks