Sub Random_Sampler_v2()
'
' Random_Sampler_v2 Macro
'
With ActiveSheet
.AutoFilterMode = False
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Apply the formula
With Range("m2:m" & lastRow)
.Formula = "=RANDBETWEEN(0,99999999999)"
End With
Sheets("Pivot").Select
ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
'Call our other macro
Call CopyAgents
End Sub
Sub CopyAgents()
Dim strName As String
Dim strCombo As String
Dim ws As Worksheet
Dim wb As Workbook
Dim rngAgents As Range
Dim c As Range
Application.ScreenUpdating = False
'Initialize values
strCombo = ""
strName = ""
With ActiveSheet
Set rngAgents = Intersect(.AutoFilter.Range.Offset(1), Range("H:H")).SpecialCells(xlCellTypeVisible)
If rngAgents Is Nothing Then
MsgBox "No visible rows"
Exit Sub
End If
Set wb = Application.Workbooks.Add
Set ws = wb.Worksheets(1)
ws.Name = "Detail Info"
For Each c In rngAgents
If c.Value <> "" Then
If c.Value <> strName Then
'New Agent
strName = c.Value
strCombo = ""
End If
If c.Offset(, -6).Value & c.Offset(, 3).Value <> strCombo Then
'New Combination
.Range(.Cells(c.Row, "A"), .Cells(c.Row, "E")).Copy ws.Cells(.Rows.Count, "A").End(xlUp).Offset(1)
strCombo = c.Offset(, -6).Value & c.Offset(, 3).Value
End If
End If
Next c
End With
Application.ScreenUpdating = True
End Sub