Sub AuditSample()
Const sName = "[COLOR=#ff0000]MySheetName"[/COLOR]
Const myOffset = [COLOR=#ff0000]10[/COLOR]
Dim cel As Range, rng As Range, msg As String
With Sheets(sName)
Set rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With
For Each cel In rng
If WorksheetFunction.RandBetween(1, 10) = 1 Then
cel.Offset(, myOffset) = "Select"
msg = msg & vbCr & cel.Row & vbTab & cel.Value
End If
Next
MsgBox msg, vbOKOnly, "Selected for audit"
End Sub
Sub AuditSheet()
Const sName = "[COLOR=#ff0000]MySheetName[/COLOR]"
Dim cel As Range, rng As Range, ws As Worksheet, r As Long
Set ws = Worksheets.Add: ws.Name = "Audit": ws.Range("A1:B1").Value = Array("Row", "Item")
r = 1
With Sheets(sName)
Set rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
End With
For Each cel In rng
If WorksheetFunction.RandBetween(1, 10) = 1 Then
r = r + 1
ws.Cells(r, 1).Resize(, 2) = Array(cel.Row, cel.Value)
End If
Next
End Sub
If you prefer the list created on a different sheet use something like this
- amend constant to name of sheet containing the data
Code:Sub AuditSheet() Const sName = "[COLOR=#ff0000]MySheetName[/COLOR]" Dim cel As Range, rng As Range, ws As Worksheet, r As Long Set ws = Worksheets.Add: ws.Name = "Audit": ws.Range("A1:B1").Value = Array("Row", "Item") r = 1 With Sheets(sName) Set rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp)) End With For Each cel In rng If WorksheetFunction.RandBetween(1, 10) = 1 Then r = r + 1 ws.Cells(r, 1).Resize(, 2) = Array(cel.Row, cel.Value) End If Next End Sub
Thank you for your support. But still the issue is not resolved. Every time the output is changing though my criteria is Same. Really can't understand why the output count is changingTo copy the whole row perhaps..
REPLACE
WITHCode:ws.Cells(r, 1).Resize(, 2) = Array(cel.Row, cel.Value)
Code:cel.Resize(, Columns.Count).Copy ws.Range("A" & Rows.Count).End(xlUp).Offset(1)